Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shell with different user rights

Posted on 2006-06-12
2
Medium Priority
?
425 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month20 days, 15 hours left to enroll

864 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