?
Solved

Shell with different user rights

Posted on 2006-06-12
2
Medium Priority
?
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
bhermer earned 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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