Solved

VB.NET RegSvr32

Posted on 2003-11-10
4
1,454 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
4 Comments
 

Expert Comment

by:zljk
Comment Utility
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
Comment Utility
...or just log on as Administrator and register the components manually.
0
 

Author Comment

by:boneal06
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now