Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

[RESOLVED] Combine 2 vbs Scripts

$
0
0
Hello to everyone
I'm trying to make a vbs script to to run a batch/cmd file elevated/with admin priviledges. Both files are in the same folder.
I also want to be able to run the script from no matter which drive or directery the folder is placed.
I mean using the equivalent of %~dp0 variable in the vbs script. Right now I have 2 vbs scripts.
One runs the cmd elevated, and the second one can run the cmd from inside the folder where they bothe are placed.
My problem: I'm unable to put the code of the 2 vbs scripts to one and a single vbs script file. As you will notice, I'm not so experienced in creating scripts. I need your help please.

First script to run cmd with admin priviledges:

Code:

et WshShell = WScript.CreateObject("WScript.Shell")
  If WScript.Arguments.length = 0 Then
  Set ObjShell = CreateObject("Shell.Application")
  ObjShell.ShellExecute "wscript.exe", """" & _
  WScript.ScriptFullName & """" &_
  " RunAsAdministrator", , "runas", 1
  Wscript.Quit
  End if

Set WinScriptHost = CreateObject("WScript.Shell")
CreateObject("Wscript.Shell").Run "cmd /k " & chr(34) & "C:\Users\xxxxx\Documents\file.cmd" & chr(34), 0, True
Set WinScriptHost = Nothing

Second script to run cmd from the same folder as the vbs script:

Code:

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
CreateObject("Wscript.Shell").Run "file.cmd",0,True

Thank You

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>