VB.NET RegSvr32

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?  

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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 CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_SEPARATE_WOW_VDM = &H800&
Private Const CREATE_SUSPENDED = &H4&
Private Const HIGH_PRIORITY_CLASS = &H80&
Private Const IDLE_PRIORITY_CLASS = &H40&

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

    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).

...or just log on as Administrator and register the components manually.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boneal06Author Commented:
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.
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.