tambrosi
asked on
How to run a windows script file with administrator rights,
Hello, I am new to this stuff, and need to get a windows script file to run with admin priv.
I use a command file. .cmd to in invoke the .wsf file.
When I try to execute this, I get a permission denied. If I right click, run as administrator -- process works.
Is there a way I can get this to runas with admin priv.
Hope I entered this correctly.
Any help would be appreciated.
.cmd file
wscript.exe D:\lsftest\terry.wsf
terry.wsf
DIM strInputFolder, strOutputFolder
strInputFolder = "D:\MainFrameFTPFiles\terr y.txt"
strOutputFolder = "D:\Dataloads\tja.txt"
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objFSO.CopyFile "D:\MainFrameFTPFiles\terr y.txt" , "D:\Dataloads\tja.txt", OverwriteExisting
wscript.echo "VBS Script running"
wscript.echo "Terry.vbs"
wscript.echo "Input Folder =" & strInputFolder
wscript.echo "Output Folder =" & strOutputFolder
I use a command file. .cmd to in invoke the .wsf file.
When I try to execute this, I get a permission denied. If I right click, run as administrator -- process works.
Is there a way I can get this to runas with admin priv.
Hope I entered this correctly.
Any help would be appreciated.
.cmd file
wscript.exe D:\lsftest\terry.wsf
terry.wsf
DIM strInputFolder, strOutputFolder
strInputFolder = "D:\MainFrameFTPFiles\terr
strOutputFolder = "D:\Dataloads\tja.txt"
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.Fi
objFSO.CopyFile "D:\MainFrameFTPFiles\terr
wscript.echo "VBS Script running"
wscript.echo "Terry.vbs"
wscript.echo "Input Folder =" & strInputFolder
wscript.echo "Output Folder =" & strOutputFolder
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the input and ideas. This is the code that got me past the permission denied issue.
If Not WScript.Arguments.Named.Ex ists("elev ate") Then
CreateObject("Shell.Applic ation").Sh ellExecute WScript.FullName _
, WScript.ScriptFullName & " /elevate", "", "runas", 1
WScript.Quit
End If
**
I need to dig into the permissions and see what is going on, but this got me past the issue for now. I need to red up on the psExec process.
Thanks
If Not WScript.Arguments.Named.Ex
CreateObject("Shell.Applic
, WScript.ScriptFullName & " /elevate", "", "runas", 1
WScript.Quit
End If
**
I need to dig into the permissions and see what is going on, but this got me past the issue for now. I need to red up on the psExec process.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I agree, I need to get to the root of the cause.
Thanks
Thanks
If it's in the section you posted above, then changing the permissions as I suggested should work.
If it's somewhere else, the first solution is to change the respective permissions so that elevation isn't required.
If the script is started from a third-party application, then the third-party application should be run elevated.
Is the whole thing supposed to be run interactively, or as a scheduled task?