Problem Creating Custom Shortcuts with VBScript

(imported topic written by jpf506791)

Hello everyone. This is my first post.

I’m currently an intern at a branch campus of a university and we’re using BigFix for the first time. We have a couple applications installed on a network drive that is mapped using Group Policy. These applications run fine from the network drive with no problem.

Today I was asked to write an ActionScript to deploy a shortcut to our computers. Here is that script:

// Using ActionScript, this will create a new VBScript file, write to it, execute it with cscript, and delete it.   
// Begin reading lines and write to the VBScript file. createfile until ENDOFFILE   
'Begin VBScript Code   
'Create a WshShell Object.  
'Allows you to run a program locally, 
'manipulate the contents of the registry, 
'create a shortcut, 
'or access a system folder. set WshShell = WScript.CreateObject(
"WScript.Shell")   
'Returns the script of the path to the special folder. Optional. 
'strSpecialFolder = WshShell.SpecialFolders("<Select a special folder below.>")   
'Available special folders: 
'AllUsersDesktop 
'AllUsersStartMenu 
'AllUsersPrograms 
'AllUsersStartup 
'Desktop 
'Favorites 
'Fonts 
'MyDocuments 
'NetHood 
'PrintHood 
'Programs 
'Recent 
'SendTo 
'StartMenu 
'Startup 
'Templates   
'Create a WshShortcut Object. 
'Can create a new shortcut, or open an existing shortcut. 
'If you are using special folders, combine paths with &. Example: strSpecialFolder & "\Shortcut.lnk" 
'Be sure that your path includes the name of the shortcut and the lnk extension. Example: "\Shortcut.lnk" set oShellLink = WshShell.CreateShortcut(
"<This is the full path to where the shortcut will be created.>")   
'Set the target path of the shortcut. oShellLink.TargetPath = 
"<This is the full path to the executable that the shortcut points to>"   
'Assign an icon to the shortcut. 
'The index is the icon index. If you're pointing to an executable, it should be 0. 
'Otherwise, if you're pointing to a dll (shell32.dll), you can specify the icon index. oShellLink.IconLocation = 
"<This is the full path to the icon location or the executable.>, 0"   
'A short description of the shortcut. Optional. 
'oShellLink.Description = "Optional Description"   
'Set the window style for the program being run. Optional. 
'1 = Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. 
'3 = Activates the window and displays it as a maximized window.  
'7 = Minimizes the window and activates the next top-level window. 
'oShellLink.WindowStyle = 1   
'Commit the changes to the shortcut and save it to the path. oShellLink.Save   
'Clean up the WshShortcut Object. set oShellLink = Nothing   ENDOFFILE 
// The previous line stops writing to the VBScript file.   
// Copy the newly created file to a filename that has a .vbs extension. copy __createfile CreateShortcut.vbs   
// Execute the VBScript silently using cscript.exe waithidden cscript.exe CreateShortcut.vbs   
// Delete the VBScript we just created. delete CreateShortcut.vbs

The VBScript portion of the code works fine when run locally on the machines.

The problem I am having is when this is deployed, if the target for the shortcut has a space (Example: “O:\Program Files”), the space is replaced with an underscore. This does not happen when just the VBScript portion is executed, so I am guessing its the way ActionScript is parsing the file. I have tried the hex value (%20) for the space, but that caused the deployment to fail.

Does anyone have any suggestions to fix this problem?

Thanks,

  • Jeff

(imported comment written by MattBoyd)

Hi Jeff,

After trying this myself, I found that this is actually an issue with the Windows IShellLink interface: http://support.microsoft.com/kb/263324 . Underscores are added and truncation may occur if the drive specified does not exist. If you try running the VBScript from your computer with a target drive letter that doesn’t exist, you can reproduce this behavior.

The drive doesn’t exist because BES Client executes this command under the SYSTEM context, which cannot see the network drives mapped on the computer. There are a few ways around this. First, you can try specifying the path to the network share instead of the mapped drive. For example, you could try using “\myserver.domain.com\Program Files\test.exe” instead of “o:\Program Files\test.exe”. In my testing, this did not produce spaces.

You can also try using the subst commands, as the KB article above suggests, but I haven’t tried this under the SYSTEM context to verify it will work.

Another thing you could try is creating the shortcut and then uploading the shortcut file itself through the BigFix Software Distribution Wizard. You may need to use the “rename” command in DOS to rename the .lnk file with a different extension before you can upload it. You could then use action script the copy the file and rename it with a .lnk extension. Again, I haven’t tried this one.

If you continue to have problems getting this to work, please let me know.

(imported comment written by jpf506791)

Hey boyd,

Thank you very much for your reply. I was able to reproduce the problem by specifying a drive that didn’t exist, as you suggested. I also read through the Knowledge Base article you linked to and now I understand why the issue was happening.

I was able to fix the issue by specifying the path to the network share instead of the mapped drive as you suggested. We redeployed the script this morning and the shortcut worked perfectly.

Thank you very much for your speedy response and excellent description, as well as multiple possible solutions to the problem. I will continue reading the forums as they are an excellent source of information!

Thanks again,

–Jeff