Solved

Shell with different user rights

Posted on 2006-06-12
2
409 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now