vb.net - VB2010: Create shortcut on desktop programmaticaly that runs as administrator -
i using way below create shortcuts on user's desktop. want them run administrator. found this, here in stackoverflow but... want same thing programmatically, not hand. idea?
here code:
private sub createshortcuts() dim newdir = appfolder.text dim wsh object = createobject("wscript.shell") wsh = createobject("wscript.shell") dim myshortcut, desktoppath desktoppath = wsh.specialfolders("desktop") myshortcut = wsh.createshortcut(desktoppath & "\application controller.lnk") myshortcut.targetpath = wsh.expandenvironmentstrings(newdir & "\application.exe") myshortcut.workingdirectory = wsh.expandenvironmentstrings(newdir) myshortcut.windowstyle = 1 myshortcut.iconlocation = newdir & "\application.exe" myshortcut.save() end sub
i think searching 'runas' command. can command line arguments target program is:
runas /savecred /user:administrator "yourprogrampathhere.exe"
just make sure user named 'administrator' exist. btw, there flag on properties window of shortcut, don't know how wshell way, solution might work. line needs change:
myshortcut.targetpath = wsh.expandenvironmentstrings("runas /savecred /user:administrator """ & newdir & "\application.exe""")
if you're wondering why put many quotation marks, don't worry. they're used escape initial quotation mark. have wonderful day, , hope program work!
edit: using prompt administrator password. must have 1 of that, because empty passwords not allowed. password saved , won't prompted again until next system reboot.
Comments
Post a Comment