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.
Related
As you see in my GPO settings
I have a VBScript and call it as a logon script via GPO in domain controller. The script is running at a logon but the parameters are not passed. Any ideas why not?
On technet they say
In Script Parameters, type the parameters you want to use as you would type them on the command line. For example, if your script included parameters called //logo (display banner) and //I (interactive mode), type: //logo //I.
So it should be possible the way I do it, right?
Because AnsgarWiechers asked:
I check if the script is running by
Set objFsoLog=CreateObject("Scripting.FileSystemObject")
outFileLog="C:\ScriptLog.txt"
Set objFileLog = objFsoLog.CreateTextFile(outFileLog,True)
objFileLog.Write "script wurde wenigstens ausgeführt" & vbCrLf
objFileLog.Close
at the beginning od the script.
And I check the parameters by this:
On Error Resume Next
Err.Clear
MsgBox WScript.Arguments(0)
If Err.Number <> 0 Then
MsgBox Err.Description
End If
On Error Resume Next
Err.Clear
MsgBox WScript.Arguments(1)
If Err.Number <> 0 Then
MsgBox Err.Description
End If
gpresult /h gives the following output for my GPO:
But the script is saved in the logon scripts:
Is it possible to run secedit in logon script ?
I wrote a script to add some COM and DCOM settings. To run it by doubble click or via cmd.exe works fine.
But it is not working as a logon script.
MsgBox is also not working at logon ......
Is it because secedit is not working at the start or because I run it via my domain controller ?
EDIT:
secedit isn´t the problem. I added some MsgBoxes to control the script at a logon and it is starting.
But the parameter I added to the GPO in the domain controler are not there. I made this :
On Error Resume Next
Err.Clear
MsgBox WScript.Arguments(0)
If Err.Number <> 0 Then
MsgBox Err.Description
End If
On Error Resume Next
Err.Clear
MsgBox WScript.Arguments(1)
If Err.Number <> 0 Then
MsgBox Err.Description
End If
And the output is "out of range" twice.
So why am I not able to set these two parameters in the GPO like this?
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
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.
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