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
tambrosiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
That's a simple file copy, there's no need for the wsf file.
A one-line batch script will do the job:
copy "D:\MainFrameFTPFiles\terry.txt" "D:\Dataloads\tja.txt"

Open in new window

As for the permissions issue: the best option is probably to create a dedicated access group for the Dataloads folder, give this group at least Change permissions on the folder, and add the user(s) running the script to this group.
There is nothing in this script that really requires elevation.
0
tambrosiAuthor Commented:
I should of explained further,  there is a lot more to the script than just the copy,  the script will be accessing datalogic, email
and a few other areas.  
I need to call the cmd file from a third party product to execute.  
Thanks
0
omgangIT ManagerCommented:
You can use PsExec to execute a command in the context of another user.  Here's an example from a vbscript I've used in the past.  The command is executing a batch file on a remote machine using the supplied username (RemUser) and password

            strFullCmd = "psexec \\" & strDestComputer & " -u " & strRemUser & " -p " & strPass _
                        & " -i -d GetHelpMsg.bat " & Chr(34) & strUserName & Chr(34)

Read up on, and download, PsExec here  https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

OM Gang
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

oBdACommented:
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?
0
tambrosiAuthor Commented:
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
0
oBdACommented:
That's basically just treating the symptoms, not the cause.
Unless you're doing something that really requires administrative permissions that can not be delegated (and so far, what you've listed should be able to run without those), you should change whatever permissions are still required so that a non-admin account can run the tasks involved.
psexec won't help you here; starting psexec does require administrative permissions (because it temporarily installs a service), so in order to start it, you will already require elevation, so at this point, you can just as well continue with the script.
0
tambrosiAuthor Commented:
I agree,  I need to get to the root of the cause.  
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.