Jump to content

Trying to migrate 2 VBScripts into one.


Recommended Posts

One of the problems I had was how the New OS Key was processed by Win 7 and Vista, if

you removed the dash between the 5 characters it would cause an error. If you leave the

dashes in then it ran without errors, that why in the V7 function there is no On Error

Resume Next.

It was not that it was hard to figure out how to merge the 2 scripts, when you break it

down to separate functions.

Thank you and I was glad to help getting the script to work.

Here is a VBS script that meant to have One File Drag Drop or Use in Cmd Line

with One File, to be run with Admin Access.

RunAsDragDrop.vbs

'-> Script By Gunsmokingman AKA Jake1Eye'->   This Script And Or Any Code Is The Property Of Gunsmokingman Or'->  Jake1Eye, Except Where Acknowledgement Comments Exists for Code'->  Written By Other Coders.'->   If Any Part Of This Code Is Used In Other Coding Project, There'->  Must Be An Acknowledgement Comments To The Original Coder Must Be '->  Included In Any Other Coding Project.'-> Objects For Runtime Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") Dim Reg :Set Reg = GetObject("winmgmts://./root/default:StdRegProv")'-> Varibles For Various Run Time Dim A, c34, Ts, Txt  c34 = Chr(34)  Txt = Act.ExpandEnvironmentStrings("%Temp%\DragDropItem.txt")'-> Makes Sure One Item Has Been Drag And Drop Or Cmd Lines Arguments A = WScript.Arguments.Count  If A = 0 Then    call Msg("You Must Drag And Drop One File" & vbCrLf & _   "Type On To This Script.", "Error No File Drop")   WScript.Quit(0)  ElseIf A >= 2 Then    call Msg("This Script Only Allow For One File To" & vbCrLf & _   "Be Drag And Drop. Total Files Drag And Drop : " & A,"Errpr To Many Files")   WScript.Quit(1)  End If '-> Original Link To Script At StackOverFlow'-> http://stackoverflow.com/questions/18504036/is-is-possible-to-have-run-as-prompt-for-vbscript'-> Script Modified By Gunsmokingman Aka Jake1eye   If Reg.GetStringValue(&h80000003, "S-1-5-19\Environment", "TEMP", val) = 5 Then   If WScript.Arguments.Count = 1 Then    MkT(WScript.Arguments.Item(0))    CreateObject("Shell.Application").ShellExecute "wscript.exe" _      , Chr(34) & WScript.ScriptFullName & Chr(34) & " relaunch", "", "runas", 1    WScript.Quit(2)    Else     call Msg("Can Not Acquire Admin Privileges", "Error No Admin Access")     WScript.Quit(3)    End If   Else'-> Code Here With Admin Access    Set Ts = Fso.OpenTextFile(Txt)     A=Ts.ReadAll      Ts.Close()    Act.Run(A),1,True    Fso.DeleteFile(Txt),True     End If'-> Makes Text File With WScript.Arguments.Item(0) Passed On'-> As Varible To Run With Admin Access   Function MkT(T)      Set Ts = Fso.CreateTextFile(Txt)    Ts.WriteLine c34 & T & c34    Ts.Close()     End Function'-> Makes All The Msgbox For The Script   Function Msg(T, L)       MsgBox T, 4128, L   End Function
Rename RunAsDragDrop.vbs.txt to RunAsDragDrop.vbs to make active

RunAsDragDrop.vbs.txt

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...