Solved

VB.NET RegSvr32

Posted on 2003-11-10
4
1,480 Views
Last Modified: 2008-02-01
I have a program that basically installs a bunch of files that sit on a Server onto the user's local machine. These files include .dlls and ocx files that are used by an VB 6 Application and  they must be registered on the local machine. The issue is with a user who doesn't have poweruser or local admin rights (Windows XP). With just this normal user profile, the program cannot successfully run the program, because the regsvr32 <dll> or <ocx> commands fail. Using a Windows Installer will not work for this type of application design.  

Any way to run the program with elevated permissions without coding in a local admin password. The problem is that this program has to run under the Projects security policy, meaning normal users essentially can't install any software.


Any clues.. Can't really create this as a windows service because there is a GUI component and this program needs to run on the users machine. Basically the regsvr32 command writes entries into the registry that a normal user does not have access to.

Any ways to get around this?  

Thanks.
0
Comment
Question by:boneal06
[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
4 Comments
 

Expert Comment

by:zljk
ID: 9721136
Hi,

I wrote the similar code recently, having the same problems as u do. There is no workaround except storing somewhere encrypted admin password, or doing it as  a service. If u store admin password somewhere, you can use WIN32 API CreateProcessWithLogon to run a new instance of the app, this time with administrative privileges:

Private Const LOGON_WITH_PROFILE = &H1&
Private Const LOGON_NETCREDENTIALS_ONLY = &H2&
Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_NEW_PROCESS_GROUP = &H200&
Private Const CREATE_SEPARATE_WOW_VDM = &H800&
Private Const CREATE_SUSPENDED = &H4&
Private Const CREATE_UNICODE_ENVIRONMENT = &H400&
Private Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000&
Private Const BELOW_NORMAL_PRIORITY_CLASS = &H4000&
Private Const HIGH_PRIORITY_CLASS = &H80&
Private Const IDLE_PRIORITY_CLASS = &H40&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const REALTIME_PRIORITY_CLASS = &H100&

Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type

Private Type STARTUPINFO
    cb As Long
    lpReserved As Long
    lpDesktop As Long
    lpTitle As Long
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Byte
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Private Declare Function CreateProcessWithLogon Lib "Advapi32" Alias "CreateProcessWithLogonW" (ByVal lpUsername As Long, ByVal lpDomain As Long, ByVal lpPassword As Long, ByVal dwLogonFlags As Long, ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

        Dim lpApplicationName As String
        Dim lpCommandLine As String, lpCurrentDirectory As String
        Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
   
        On Error GoTo hell
   
       lpApplicationName = App.Path & "\" & App.EXEName & ".exe"
       lpCommandLine = Command$ & sCommandLine
   
      lpCurrentDirectory = CurDir$ & "\" 'use standard directory
      StartInfo.cb = LenB(StartInfo) 'initialize structure
      StartInfo.dwFlags = 0&
       
      If CreateProcessWithLogon(StrPtr(sUname), StrPtr(sDomain), StrPtr(sPWD), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), StrPtr(lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), StartInfo, ProcessInfo) = 0 Then
         lError = Err.LastDllError
         MsgBox GetApiErrDesc(lError), vbCritical
        End If
   
       CloseHandle ProcessInfo.hThread
       CloseHandle ProcessInfo.hProcess

That's it. If MS would allow anyone to override security policy, that wouldn't be a security policy anyway :) So you do need username and password of the user that has rights to install new components, or u must run app under local system account - as a service (that is installed by an administrator anyway).


0
 
LVL 8

Accepted Solution

by:
bukko earned 500 total points
ID: 9721471
...or just log on as Administrator and register the components manually.
0
 

Author Comment

by:boneal06
ID: 9725163
Ok. I think that's the way I'll go. One more thing. What's the best way to encript then unencript the userid and password, so that I can use in the program.
0
 

Expert Comment

by:freemanjennifer04
ID: 11529136
The problem with logging in as an Administrator and registering the component manually is that we have over 2,000 computers and we have 10 offices globally. That is definitely not an option unfortunately. Thanks.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
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…
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…
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…

705 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