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
Solved

Shell with different user rights

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

861 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