Link to home
Start Free TrialLog in
Avatar of tambrosi
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\terry.txt"
strOutputFolder = "D:\Dataloads\tja.txt"

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "D:\MainFrameFTPFiles\terry.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
SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oBdA
oBdA

Where exactly do you get the Access denied?
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?
Avatar of tambrosi

ASKER

Thanks for the input and ideas.  This is the code that got me past the permission denied issue.  

If Not WScript.Arguments.Named.Exists("elevate") Then
  CreateObject("Shell.Application").ShellExecute 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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree,  I need to get to the root of the cause.  
Thanks