Issue running vbs script on windows 7 machine

The script works fine on windows 7 and 10 when ran from desktop manually without bigfix. But when I run it works in windows 10 but not in windows 7 machines.

I’m adding the script in software wizard and running it with .bat file.

Contents of .bat file

cd c:\windows\syswow64
cscript.exe "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\__Download\PointPrintertoNewServer.vbs"

Contents of Vbs script

'This script works well in a login script. When ran from a workstation 
'it will loop thru all of the printers installed for the current logged on 
'user and if they are connected to the old server they will be removed 
'and then remaped to the new server. It will also attempt to descover 
'which printer is the default printer in order to reset this if it is one 
'of the printers that will be moved. 
' 
'Note: All of the printers must exist on the new server before this script 
' should be run. If not then the printer will simply be removed from 
' users profile and the script will not be able to reconnect them. 
' "Print Migrator" is a utility that is part of the Windows 2000 and 
' Windows 2003 resource kit. This will create all of the printers 
' on the new server while maintaining all of their settings including 
' print queue security. Keep in mind that for a time you will see 
' duplicate printer if you do a search on printers, one advertisec 
' from each server. 
' 
'We used this method to move just over 100 printers from one server to another 
'and then ran this script as a logon script in a group policy. We let it run for 
'a few days in order to allow for some users who don't logout every day have a 
'chance to run it. All of our users profiles were updated and they didn't even 
'know it was happening. We then deleted all of the printers from the old server. 
' 
'Note: The script does not run if you are Terminal serviced or SMS remote controling. 
 
 
Option Explicit 
Dim from_sv, to_sv, PrinterPath, PrinterName, DefaultPrinterName, DefaultPrinter 
Dim DefaultPrinterServer, SetDefault, key 
Dim spoint, Loop_Counter, scomma 
Dim WshNet, WshShell 
Dim WS_Printers 
DefaultPrinterName = "" 
spoint = 0 
scomma = 0 
SetDefault = 0 
set WshShell = CreateObject("WScript.shell") 
 
from_sv = "\\bna62s02" 'This should be the name of the old server. 
to_sv = "\\bna62s01" 'This should be the name of your new server. 
 
 
'Just incase their are no printers and therefor no defauld printer set 
' this will prevent the script form erroring out. 
On Error Resume Next 
key = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device" 
DefaultPrinter = LCase(WshShell.RegRead (key)) 
 
 
If Err.Number <> 0 Then 
    DefaultPrinterName = "" 
else 
'If the registry read was successful then parse out the printer name so we can  
' compare it with each printer later and reset the correct default printer 
' if one of them matches this one read from the registry. 
spoint = instr(3,DefaultPrinter,"\")+1 
 
  
 
DefaultPrinterServer = left(DefaultPrinter,spoint-2) 
 
    if lcase(DefaultPrinterServer) = from_sv then 
        DefaultPrinterName = mid(DefaultPrinter,spoint,len(DefaultPrinter)-spoint+1) 
        scomma = instr(DefaultPrinterName,",") 
        DefaultPrinterName = left(DefaultPrinterName,scomma -1) 
    end if 
end if 
 
Set WshNet = CreateObject("WScript.Network") 
Set WS_Printers = WshNet.EnumPrinterConnections 
 
'You have to step by 2 because only the even numbers will be the print queue's 
' server and share name. The odd numbers are the printer names. 
For Loop_Counter = 0 To WS_Printers.Count - 1 Step 2 
    'Remember the + 1 is to get the full path ie.. \\your_server\your_printer. 
    PrinterPath = lcase(WS_Printers(Loop_Counter + 1)) 
 
    'We only want to work with the network printers that are mapped to the original 
    ' server, so we check for "\\Your_server". 
    if lcase(LEFT(PrinterPath,len(from_sv))) = from_sv then 
        'Now we need to parse the PrinterPath to get rhe Printer Name. 
        spoint = instr(3,PrinterPath,"\")+1 
        PrinterName = mid(PrinterPath,spoint,len(PrinterPath)-spoint+1) 
        'Now remove the old printer connection. 
        WshNet.RemovePrinterConnection from_sv+"\"+PrinterName 
        'and then create the new connection. 
        'Do not create c6100 
        if lcase(PrinterName) <> "c6100" then 
            WshNet.AddWindowsPrinterConnection to_sv+"\"+PrinterName 
            'If this printer matches the default printer that we got from the registry then 
            ' set it to be the default printer. 
            if DefaultPrinterName = PrinterName then 
                WshNet.SetDefaultPrinter to_sv+"\"+PrinterName 
            end if 
        end if 
    end if 
Next 
Set WS_Printers = Nothing 
Set WshNet = Nothing 
Set WshShell = Nothing 

I’ve already tried Runascurrent vbs script

I’m also placing wow64 redirection in the script

action uses wow64 redirection false

there’s nothing in the logs that says that it failed, but I’m attaching it here.

Current Date: September 25, 2019
   Client version 9.5.12.68 built for WINVER 6.0 i386 running on WINVER 6.1.7601 x86_64
   Current Balance Settings: Use CPU: True Entitlement: 0 WorkIdle: 10 SleepIdle: 480
   ICU 54.1 init status: SUCCESS
   Agent internal character set: UTF-8
   ICU report character set: UTF-8 - Transcoding Disabled
   ICU fxf character set: windows-1252 (Latin 1 / Western European) - Transcoding Enabled
   ICU local character set: windows-1252 (Latin 1 / Western European) - Transcoding Enabled
At 18:20:02 -0400 - 
   Starting client version 9.5.12.68
   FIPS mode disabled by default.
At 18:20:03 -0400 - 
   Cryptographic module initialized successfully.
   Using crypto library libBEScrypto - OpenSSL 1.0.2q  20 Nov 2018
At 18:20:04 -0400 - 
   Initializing Site: actionsite
   Restricted mode
   Initializing Site: Advanced Patching
   Initializing Site: BES Asset Discovery
   Initializing Site: BES Inventory and License
   Initializing Site: BES Support
   Initializing Site: BigFix Labs
   Initializing Site: CustomSite_Development
   Initializing Site: CustomSite_swd_app_group
   Initializing Site: Enterprise Security
At 18:20:05 -0400 - 
   Initializing Site: Patching Support
   Initializing Site: Software Distribution
   Initializing Site: Updates for Windows Applications
   Initializing Site: mailboxsite
   Processing Download plugins
At 18:20:06 -0400 - 
   PeerNest: configure peer nest: Enabled: True; IsPassive: False; Priority: 100; Timeout: 30
   Beginning Relay Select
At 18:20:07 -0400 - 
   RegisterOnce: Attempting secure registration with 'https://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfenterprise/clientregister.exe?RequestType=RegisterMe60&ClientVersion=9.5.12.68&Body=1610983847&SequenceNumber=305&MinRelayVersion=7.1.1.0&CanHandleMVPings=1&Root=http://NE-PRD-BFIX01.nittsu.com%3a52311&AdapterInfo=68-f7-28-0c-f0-cc_10.254.7.0%2f24_10.254.7.110_0'
At 18:20:08 -0400 - 
   Unrestricted mode
   Configuring listener without wake-on-lan
   Registered with url 'https://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfenterprise/clientregister.exe?RequestType=RegisterMe60&ClientVersion=9.5.12.68&Body=1610983847&SequenceNumber=305&MinRelayVersion=7.1.1.0&CanHandleMVPings=1&Root=http://NE-PRD-BFIX01.nittsu.com%3a52311&AdapterInfo=68-f7-28-0c-f0-cc_10.254.7.0%2f24_10.254.7.110_0'
   Registration Server version 9.5.12.68 , Relay version 9.5.12.68
   Relay does not require authentication.
   Client has an AuthenticationCertificate
   Relay selected: NE-PRD-BFIX01.nittsu.com. at: 10.254.205.112:52311 on: IPV4 (Using setting IPV4ThenIPV6)
At 18:20:14 -0400 - 
   PollForCommands: Requesting commands
At 18:20:15 -0400 - 
   PollForCommands: commands to process: 0
At 18:20:17 -0400 - 
   Entering Service Loop.
   Starting Service Loop.
   A2AServer::Start().
   PollForCommands: Requesting commands
   PollForCommands: commands to process: 0
   Successful Synchronization with site 'actionsite' (version 2347) - 'http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/actionsite'
At 18:20:18 -0400 - 
   Site 'mailboxsite' is not yet available on selected relay.  Awaiting notification of availability.
   Successful Synchronization with site 'mailboxsite' (version 0) - 'http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/mailboxsite1610983847'
At 18:20:20 -0400 - 
   ActiveDirectory: Refreshed Computer Information - Domain: NEUSA
   ActiveDirectory: User logged in - Domain: NEUSA User: Cointa_Perez
   User interface process started for user 'Cointa_Perez'
   [ThreadTime:18:20:17] SetupListener success: IPV4/6
   [ThreadTime:18:20:17] PeerNest: cannot join the multicast ipv6 group: 10049
   ActiveDirectory: Refreshed User Information - Domain: NEUSA User: Cointa_Perez
At 18:20:21 -0400 - 
   ActionLogMessage: (action:835) Action signature verified for Downloads
At 18:20:30 -0400 - 
   Encryption: optional encryption with no certificate; reports in cleartext
At 18:21:55 -0400 - 
   Report posted successfully
At 18:27:41 -0400 - 
   GatherHashMV command received.
At 18:27:43 -0400 - mailboxsite (http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/mailboxsite1610983847)
   Downloaded 'http://NE-PRD-BFIX01.nittsu.com:52311/mailbox/files/f4/bd/f4bd9a0d69942457279d13ee71e3afb9f954ba44' as 'Action 1725.fxf'
   Gather::SyncSiteByFile adding files - count: 1
At 18:27:43 -0400 - 
   Successful Synchronization with site 'mailboxsite' (version 1) - 'http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/mailboxsite1610983847'
At 18:27:44 -0400 - 
   Processing action site.
   DownloadPing command received (ID=1725)
At 18:27:44 -0400 - mailboxsite (http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/mailboxsite1610983847)
   Relevant - Deploy "BNA62S02 > BNA62S01" Files - Loaner2 - 09252019 - 527PM (fixlet:1725)
At 18:27:44 -0400 - 
   ActionLogMessage: (action:1725) Action signature verified for Downloads
At 18:28:32 -0400 - 
   Report posted successfully
At 18:28:38 -0400 - 
   DownloadsAvailable: checking for 'http://NE-PRD-BFIX01.nittsu.com:52311/bfmirror/downloads/1725/0'
   DownloadsAvailable: true (action id 1725)
   DownloadsAvailable: checking for 'http://NE-PRD-BFIX01.nittsu.com:52311/bfmirror/downloads/1725/0'
   DownloadsAvailable: true (action id 1725)
   ActionLogMessage: (action:1725) Non-Distributed - DownloadsAvailable
   ActionLogMessage: (action:1725) Submitting download request
   ActionLogMessage: (action:1725) Download url: 'SWDProtocol://127.0.0.1:52311/Uploads/57EF2A3C732DB9B304A382857983C46E3520299F/PointPrintertoNewServer.vbs.bfswd'
   ActionLogMessage: (action:1725) Download url: 'SWDProtocol://127.0.0.1:52311/Uploads/DFD8A5822319C94FFC18774D4329A92E2D4E88C7/ChangeServer.bat.bfswd'
At 18:28:39 -0400 - 
   ActionLogMessage: (action:1725) Action signature verified for Execution
   ActionLogMessage: (action:1725) starting action
At 18:28:40 -0400 - actionsite (http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded parameter "baseFolder" =  "__Download/" (action:1725)
   Command succeeded move "__Download/57EF2A3C732DB9B304A382857983C46E3520299F" "__Download/PointPrintertoNewServer.vbs"  (action:1725)
   Command succeeded move "__Download/DFD8A5822319C94FFC18774D4329A92E2D4E88C7" "__Download/ChangeServer.bat"  (action:1725)
   Command succeeded parameter "mainSWDLogFolder" = "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData/__Global/SWDDeployData" (action:1725)
   Command succeeded folder create "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData/__Global/SWDDeployData" (action:1725)
   Command succeeded parameter "logFile" = "SWD_DeploymentResults.log" (action:1725)
   Command succeeded delete No 'C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\__createfile' exists to delete, no failure reported (action:1725)
   Command succeeded parameter "outsideOfClientFolder" = "C:\SWD_Download\action_1725\__Download" (action:1725)
   Command succeeded folder delete No 'C:\SWD_Download\action_1725\__Download' exists to delete, no failure reported (action:1725)
   Command succeeded folder create "C:\SWD_Download\action_1725\__Download" (action:1725)
   Command succeeded parameter "logFolder" = "C:\SWD_Download\action_1725" (action:1725)
   Command succeeded delete No 'C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\run.bat' exists to delete, no failure reported (action:1725)
   Command succeeded createfile until  (action:1725)
   Wow64 redirection disabled. action uses wow64 redirection false (action:1725)
   Command succeeded move __createfile run.bat (action:1725)
   Command started - waithidden cmd /C copy /Y run.bat "C:\SWD_Download\action_1725\__Download" (action:1725)
   Command succeeded (Exit Code=0) waithidden cmd /C copy /Y run.bat "C:\SWD_Download\action_1725\__Download" (action:1725)
   Command started - waithidden cmd /C xcopy /Y /E "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\__Download" "C:\SWD_Download\action_1725\__Download" (action:1725)
   Command succeeded (Exit Code=0) waithidden cmd /C xcopy /Y /E "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\__Download" "C:\SWD_Download\action_1725\__Download" (action:1725)
   Command succeeded override wait (action:1725)
   Command succeeded override runas=currentuser (action:1725)
   Command succeeded override completion=job (action:1725)
   Command succeeded override hidden=true (action:1725)
   Command started - wait "C:\SWD_Download\action_1725\__Download\run.bat" (action:1725)
At 18:28:41 -0400 - actionsite (http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/actionsite)
   Relevant - Pending Restart Action (fixlet:192)
   Relevant - Restart Endpoint on Pending Restart and Wait for Restart to Complete (fixlet:520)
   Command succeeded (Exit Code=1) wait "C:\SWD_Download\action_1725\__Download\run.bat" (action:1725)
   Command succeeded parameter "returnCode" = "1" (action:1725)
   Command started - waithidden cmd /C type "C:\SWD_Download\action_1725\SWD_DeploymentResults.log" >> "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData/__Global/SWDDeployData\SWD_DeploymentResults.log" (action:1725)
   Command succeeded (Exit Code=0) waithidden cmd /C type "C:\SWD_Download\action_1725\SWD_DeploymentResults.log" >> "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData/__Global/SWDDeployData\SWD_DeploymentResults.log" (action:1725)
At 18:28:42 -0400 - actionsite (http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded delete "C:\SWD_Download\action_1725\SWD_DeploymentResults.log" (action:1725)
   Command succeeded folder delete "C:\SWD_Download\action_1725" (action:1725)
   Command succeeded folder delete "C:\SWD_Download" (action:1725)
   Command succeeded (1) exit {parameter "returnCode"} (action:1725)
At 18:28:42 -0400 - 
   ActionLogMessage: (action:1725) ending action
At 18:28:42 -0400 - mailboxsite (http://NE-PRD-BFIX01.nittsu.com:52311/cgi-bin/bfgather.exe/mailboxsite1610983847)
   Not Relevant - Deploy "BNA62S02 > BNA62S01" Files - Loaner2 - 09252019 - 527PM (fixlet:1725)
At 18:30:20 -0400 - 
   Report posted successfully

Please assist.

The .bat is returning an exist code = 1

Command succeeded (Exit Code=1) wait "C:\SWD_Download\action_1725__Download\run.bat"
Command succeeded parameter “returnCode” = “1” (action:1725)

If not already done, then try to test the “exit code” of you .bat from the command line on the failing Windows 7 machine. (echo $?)

I’m not sure what that means. I have a .bat file content up in the post.

Can you please make the change and show me what I should do. I’m totally new to this.

Sorry for being not very clear.
The BES agent log indicates that the return code of your “run.bat” program is 1 (Command succeeded parameter “returnCode” = “1” )

Any exit code different from “0” are considered a failing condiction by BES acton.

Thus, I am suggesting to test the .bat file from the command line on the failing machine, in order to check the exit code. You can use the $? or add a statement to print the %errorlevel% at the end of the bat file

cd c:\windows\syswow64
cscript.exe “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\actionsite__Download\PointPrintertoNewServer.vbs”

If that is literally the file you’re running, you’ll have some problems with it. The “normal” user account, which you’re impersonating with either RunAsCurrentUser.exe or with the ‘override wait’ options, can’t access the __BESData folder.

The SWD wizard is already creating a new folder at C:\SWD_Download; depending on your system configuration, I think a standard user account should be able to read/write that folder, and the run.bat is being executed from "C:\SWD_Download\action_1725\__Download\run.bat", so you may be able to use relative pathing. Instead of having the run.bat call out the full path to PointPrintertoNewServer.vbs, use the CMD shell relative pathing to look for “PointPrintertoNewServer.vbs in the same directory as run.bat” via

cscript.exe "%~dp0PointPrintertoNewServer.vbs"

%~dp0 evaluates to “Drive Letter and Path of Parameter 0 (the run.bat script itself)”`

1 Like

Can you try running this VBScript by hand on a system that is having trouble with it using PSExec as SYSTEM account? This is one of the better ways to approximate the user environment BigFix will run it under when not using “as current user” methods. Does your script actually require running as a non-SYSTEM user?

Here are some examples that us VBScript:

This may actually conflict with the other parts of your script, also this is not how I would do it. I just do waithidden cmd /c cscript to invoke.