can't map network drive from task scheduler - was working - vbscript

We have a vbs file on our local server (A) that uses mapnetworkdrive to contact two servers at a remote location (B) and copy files from B to A. The script has been running for about 3 months with no problems. Since last week, the script has been unable to map the network drive to B if it runs from Task Scheduler, but it works fine when run from the command line or by double-clicking on the vbs file.
I know the script is running because it logs things as it runs. One of those is the error message when it tries to map the network drive. It looks like this:
boh_mapped_drive_letter = "w:"
boh_mapped_drive = "\\xxx.xxx.xxx.xxx\sharename"
NetworkObject.MapNetworkDrive boh_mapped_drive_letter, boh_mapped_drive, False, <username>, <password>
if err.number <> 0
appendToFile logfile, vbtab & "error occurred - " & vbtab & err.number & " " & err.source & " " & err.description
Err.Clear
end if
and the error I get is:
53 Microsoft VBScript runtime error File not found
What could cause the scheduled task to not be able to map the network drive but it still works by manually executing it?
When you double-click or CLI execute a vbs file, what user account does it run under? Is it different from the user account that runs it from Task Scheduler?

Looks like we were able to fix it by checking the "Run with Highest Privileges" box.

Related

Self-elevating VBS from mapped network drive not working

Here is my sample test code:
On Error Resume Next
Dim localServiceKey : localServiceKey = CreateObject("WScript.Shell").RegRead("HKEY_USERS\s-1-5-19\")
'On error, elevate the script
If Err.Number <> 0 Then
CreateObject("Shell.Application").ShellExecute WScript.FullName, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1
Err.Clear
WScript.Quit()
End If
...INSERT CODE BELOW...
This self-elevating VBS script file works properly if I run it from a local drive or from a network drive accessed using UNC (ie: \\server\folder).
But if I run it from a mapped drive (ie: Z:\folder), I receive an error after the UAC prompt stating:
Can not find script file...
Is there a work around for allowing VBS script file to run from a mapped network drive?
NOTE: I'm testing this code on Windows 10 x64.
Thanks for any advice.

VB Window Services batch not executing

I am executing a batch file by using VB run method to connect ftp.
When I am executing VB code in debugging mode batch file is executing without any issue and ftp is successful. But, after building the exe file and tried to run it thorough windows service batch file is not executing.
command = Chr(34) & "FTPconnection.bat" & Chr(34) & " " & moReportFile
a.Run command, 0, True

Stopping Multiple Services Windows 7 using VBScript

During my internet searches, I have found a script that is supposed to stop a service. The current script runs, finds the services specified in an array, but doesn't seem to stop them. When the script outputs the services' State, it's still running. Below is the script.
sComputer = "."
aTargetSvcs= Array("mysql","Apache2.4")
Set oWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\" _
& sComputer & "\root\cimv2")
Set cServices = oWMIService.ExecQuery("SELECT * FROM Win32_Service")
For Each oService In cServices
For Each sTargetSvc In aTargetSvcs
If LCase(oService.Name) = LCase(sTargetSvc) Then
If oService.State <> "Stopped" Then
oService.StopService()
Wscript.Echo oService.State
End If
End If
Next
Next
I am just testing it out with mysql and Apache2.4 services, but when this works, it will be deployed with a group policy to temporarily stop some AV services that are interfering with a domain modifier script.
The issue is likely a lack of permission in the context of the running script.
If you run the script from the command line make sure to start it through an Elevated Command Prompt, in modern Windows Operating Systems an elevated Command Prompt is denoted by the prefix Administrator: in the Window Title.
If you run the script from a Shortcut link make sure to specify Run As Administrator in the Advanced Properties screen.

Log on as local administrator in VBS

I have what should be a very simple script. I have a series of 6 PCs that I need to check the existence of a file and report back. Where the difficulty lies is that these devices are not part of AD and are part of a work group. From windows explorer using C$ I'm prompted to log on as a local administrator on the remote PC. How can I perform the same logon and automate the process using the script below?
Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 1 To 6
If objFSO.FileExists("\\10.4.55." & i & "\c$\Program Files\X-1 Technologies\offline.fla") Then
Wscript.Echo "Reg:" & i & " Off-Line."
Else
Wscript.Echo "Reg:" & i & " On-Line."
End If
Next
Thanks, Lloyd

mstsc Remote Desktop questions

currently, to improve some inefficiencies on a daily process, I am trying to write a c# Winform app that will combine a mix of user-input with VBscripts that will expedite a previously all user-input process of looking at an excel file and moving files from VSS to certain folders of certain servers.
I was hoping to get some questions answered, pointed in the right way:
Using command line or other workaround instead of manually,
1) Is it possible to log into a 2003 remote desktop with a Smartcard/pin?
2) Is it possible to run a file/start a process on the remote desktop from a command on your machine?
Thanks for the help and time
I have only experience with the second question.
You can do this with remote scripting or with utilities like SysInternals PsExec http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
here a vbscript that remotely starts a ipconfig command and redirects it to a textfile
Note that you can't start interactive processes like this, they would start but not show up
Dim sComputer 'computer name
Dim sCmdLine 'command line of the process
Dim sCurDir 'working directory of the process
Dim oProcess 'object representing the Win32_Process class
Dim oMethod 'object representing the Create method
sComputer = "." 'this is the local computer, use a pcname or ip-adress to do it remote
sCmdLine = "cmd /c ipconfig.exe > c:\ipconfig.txt"
Set oProcess = GetObject("winmgmts://" & sComputer & "/root/cimv2:Win32_Process")
Set oMethod = oProcess.Methods_("Create")
Set oInPar = oMethod.inParameters.SpawnInstance_()
oInPar.CommandLine = sCmdLine
oInPar.CurrentDirectory = sCurDir
Set oOutPar = oProcess.ExecMethod_("Create", oInPar)
If oOutPar.ReturnValue = 0 Then
WScript.Echo "Create process method completed successfully"
WScript.Echo "New Process ID is " & oOutPar.ProcessId
Else
WScript.Echo "Create process method failed"
End If

Resources