Solved

Shell with different user rights

Posted on 2006-06-12
2
412 Views
Last Modified: 2008-03-04
Hi guys,
how can I execute a command shell from my vb application, with a different user rights??
This means that if I launch he application from my windows user session, I would like to execute the shell command impersonating "administrator account".
Is it possible to do?
 
thanks
0
Comment
Question by:pzilioli
2 Comments
 
LVL 4

Accepted Solution

by:
bhermer earned 250 total points
ID: 16884217
Found this on Google,

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:username ""d:\Program.exe"""
WScript.Sleep 100
WshShell.Sendkeys "password~"

It is in VBS, but you could always write this out to a temp direccoty and then run it using shell??


Something like:Dim StrProgramPath As String
StrProgramPath = "D:\program.exe"

Dim StrPassword As String
StrPassword = "1oDDJoB"

Dim StrUsername As String
StrUsername = "administrator"

Open Environ("TEMP") & "\temp.vbs" For Output As 1

Print #1, "set WshShell = CreateObject(" & Chr(34) & "WScript.Shell" & Chr(34) & ")"
Print #1, "WshShell.Run " & Chr(34) & "runas /user:" & StrUsername & " " & Chr(34) & Chr(34) & StrProgramPath & Chr(34) & Chr(34) & Chr(34)
Print #1, "WScript.Sleep 100"
Print #1, "WshShell.Sendkeys " & Chr(34) & StrPassword & "~" & Chr(34)
Close 1
Dim PathToRun As String
PathToRun = "wscript.exe " & Environ("TEMP") & "\temp.vbs"
Shell PathToRun
Kill Environ("TEMP") & "\temp.vbs"
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 16890001
How to impersonate a user from Active Server Pages
http://support.microsoft.com/default.aspx?scid=kb;EN-US;248187


You can change the ASP example from the HOW TO article and just call those functions normally from VB.

Call Logon(etc..)

Call Logoff
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question