Can anyone tell me why the following script does not work in a batch file when run as a Bigfix task? I know that Bigfix runs in 32 bit mode, but I was hoping by pointing to the 64 bit version of cscript.exe, that would resolve the issue but it did not. The issue is that the target path is getting modified to “c:\program files” on 64 bit machines when the vbscript modifies a shortcut.
if defined ProgramFiles(x86) (
%Windir%\system32\cscript.exe //nologo //B //h:cscript //s “%~dp0MochasoftShortcutMod.vbs”
) else (
%Windir%\syswow64\cscript.exe //nologo //B //h:cscript //s “%~dp0MochasoftShortcutMod.vbs”
)
I will try running the vbscript as follows:
// Disable wow64 redirection on x64 OSes
action uses wow64 redirection {not x64 of operating system}
// Run VBScript to add /SSL to Mochasoft Shortcuts
waithidden cmd.exe /C cscript //nologo //h:cscript //s {parameter “scriptPath”}\MochasoftShortcutMod.vbs
I think you’re on the right path, see how disabling wow64 redirection works for you.
I don’t think calling Windows\syswow64 is what you’d want, that’s explicitly the 32-bit binaries. I think what you’re looking for is \Windows\sysnative. But you shouldn’t need any of those tricks if you just disable wow64 redirection to begin with.
This is what I have, but it is still not working. The shortcuts are being changed from c:\program files (x86) to c:\program files. The log output is below. BTW the vbscript works perfectly when I run it manually.
// Disable wow64 redirection on x64 OSes
action uses wow64 redirection {not x64 of operating system}
// Run VBScript to add /SSL to Mochasoft Shortcuts
waithidden cmd.exe /C cscript.exe //nologo //h:cscript //s “{parameter “basefolder”}”\MochasoftShortcutMod.vbs
Log file output:
Wow64 redirection disabled. action uses wow64 redirection {not x64 of operating system} (action:411166)
Command started - waithidden cmd.exe /C cscript.exe //nologo //h:cscript //s “__Download/”\MochasoftShortcutMod.vbs (action:411166)
At 10:58:47 -0700 - actionsite (http.com:52311/cgi-bin/bfgather.exe/actionsite)
Command succeeded (Exit Code=0) waithidden cmd.exe /C cscript.exe //nologo //h:cscript //s “__Download/”\MochasoftShortcutMod.vbs (action:411166)
Command succeeded parameter “returnCode” = “0” (action:411166)
Hard to troubleshoot when we’re only guessing at what the vbscript is doing.
Here is the vbscript. I don’t think the vbscript is the problem though since it runs fine when run from a system level command prompt.
sTargetStrOldx64 = "C:\Program Files (x86)\MochaSoft\Mocha TN5250 for Vista\tn5250.exe"
sTargetStrOldx86 = "C:\Program Files\MochaSoft\Mocha TN5250 for Vista\tn5250.exe"
Set oShell = CreateObject("WScript.Shell")
strDir = "C:\Users"
Set FSO1 = CreateObject("Scripting.FileSystemObject")
Set objDir = FSO1.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(objDir)
For Each aFile In objDir.Files
If Err.number = 0 Then
On Error Goto 0
If LCase(FSO1.GetExtensionName(aFile)) = "lnk" Then
'msgBox "Found lnk: " & aFile.path
Set oLnk = oShell.CreateShortcut(aFile)
'msgbox "olnk = " & olnk
If LCase(oLnk.TargetPath) = LCase(sTargetStrOldx64) or LCase(oLnk.TargetPath) = LCase(sTargetStrOldx86) Then
If Instr(oLnk.arguments, "/SSL") >0 then
else
oLnk.arguments = oLnk.arguments & " /SSL"
'msgbox "oLnk.arguments = " & oLnk.arguments
oLnk.Save
End if
End if
End If
End If
Next
For Each aItem In objDir.SubFolders
On Error Resume Next
If Err.number = 0 Then
getInfo(aItem)
End If
Next
'msgbox "Done"
End Sub
Very strange, I don’t see why that should occur.
The problem ended up being the shortcuts I was working with. It had nothing to do with Bigfix or WOW64 redirection. The shortcuts I was working with were very old and had c:\program files baked into them. Even though my vbscript was changing the target to c:\program files (x86) on 64 bit machines when the script saved the shortcut, the target changed back to c:\program files.
The solution was to change the VBscript to delete the shortcuts, and then add them back. Here is the script I used.
'This script appends “/SSL” to the argument of all of the Mochasoft shortcuts that do not already have it.
sTargetStrOldx64 = "C:\Program Files (x86)\MochaSoft\Mocha TN5250 for Vista\tn5250.exe"
sTargetStrOldx86 = “C:\Program Files\MochaSoft\Mocha TN5250 for Vista\tn5250.exe"
progFiles=“c:\program files” & " (” & “x86” & “)”
Set oShell = CreateObject(“WScript.Shell”)
strDir = "C:\Users"
Set FSO1 = CreateObject(“Scripting.FileSystemObject”)
Set objDir = FSO1.GetFolder(strDir)
getInfo(objDir)
Sub getInfo(objDir)
For Each aFile In objDir.Files
If Err.number = 0 Then
On Error Goto 0
If LCase(FSO1.GetExtensionName(aFile)) = "lnk" Then
Set oLnk = oShell.CreateShortcut(aFile)
If LCase(oLnk.TargetPath) = LCase(sTargetStrOldx64) or LCase(oLnk.TargetPath) = LCase(sTargetStrOldx86) Then
If Instr(oLnk.arguments, "/SSL") >0 then
else
aFile2 = aFile
'Delete shortcut
FSO1.DeleteFile aFile
On Error Resume Next
'Recreate shortcut
Set oLnk2 = oShell.CreateShortcut(aFile2)
oLnk2.WorkingDirectory = oLnk.WorkingDirectory
oLnk2.TargetPath = oLnk.TargetPath
oLnk2.arguments = oLnk.arguments & " /SSL"
oLnk2.Save
End if
End if
End If
End If
Next
For Each aItem In objDir.SubFolders
On Error Resume Next
If Err.number = 0 Then
getInfo(aItem)
End If
Next
'msgbox "Done"
End Sub