Originariamente inviato da LeleFT
"Fa un po' quello che gli pare": io ho bisogno di creare un link ad un file, passare a questo dei parametri, senza utilizzare le virgolette (il file che viene richiamato è un interprete e se sulla riga di comando si mettono le virgolette questo interprete interpreta male i parametri [scusate il gioco di parole]).
Così succede che se ho un collegamento al file Pippo.exe, le proprietà del collegamento creato mi mostrano la scritta Pippo.exe (senza virgolette). Se devo passare anche dei parametri, ecco cosa mi trovo nelle proprietà del collegamento:
codice:
"Pippo.exe parametro1 parametro2"
Questo perchè ci sono gli spazi... benissimo, allora voglio poter aggiungere le virgolette io, come desidero altrimenti il collegamento non funziona. Aggiungo nello script il Chr(34) dove mi serve... niente: mi dice carattere non valido.
Così ho abbandonato lo script.
Per inserire delle virgolette in una stringa in VBS è sufficiente inserire una doppia virgoletta; ad esempio per inserire questa frase:
codice:
E MItaly disse: "ho ragione io".
Dovrai scrivere:
codice:
stringa="E MItaly disse: ""ho ragione io"""
Io non ho l'SDK della Microsoft e non ho intenzione di scaricarlo... mi serve in questa occasione, poi più niente.
Proprio non si può fare utilizzando qualche API di Windows?
Le dichiarazioni delle API di Windows stanno negli header forniti con l'SDK... se ce li hai già allora il problema non si pone.
In ogni caso copio papale papale un esempio dalla documentazione SDK:
codice:
// CreateLink - uses the Shell's IShellLink and IPersistFile interfaces
// to create and store a shortcut to the specified object.
//
// Returns the result of calling the member functions of the interfaces.
//
// Parameters:
// lpszPathObj - address of a buffer containing the path of the object.
// lpszPathLink - address of a buffer containing the path where the
// Shell link is to be stored.
// lpszDesc - address of a buffer containing the description of the
// Shell link.
HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(&IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
// TODO: Check return value from MultiByteWideChar to ensure
success.
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
La funzione in questione crea un link al file specificato.