0

Trying to execute a simple dns flush remotely from a machine, but for one reason or the other - I need to run the cmd as admin. The cmd runs fine under the account physically in person, but you need to do the whole right click -> run as admin bit.

Right now, remotePC is set to local or '.'

 Set shl = WScript.CreateObject("WScript.Shell")

'Input remote PC
 remotePC = "."

'Command which will be executed
 strCommand = "cmd.exe /C cd C:\WINDOWS\system32 & ipconfig.exe /flushdns & pause"

'Connect to the remote PC
'Impersonate with the default level?
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & remotePC & "\root\cimv2")

Set objProcess = objWMIService.Get("Win32_Process")

errReturn = objProcess.Create(strCommand, null, null, intProcessID)

1 Answer 1

1

Use PsExec for this purpose. Don't bother with VBScript.

Sign up to request clarification or add additional context in comments.

4 Comments

I still need to script this though. It needs to be automatic not manual.
I made a VBscript to automatically run PsExec, but even with PsExec and loggin in with credentials - it still asks for elevated command prompt.
Got it! Used -s with PsExec in the VBscript
wshShell.run("cmd /k psexec \\REMOTEPC -u userhere -p " & password & " -s ipconfig /flushdns")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.