Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.NET RegSvr32

Posted on 2003-11-10
4
Medium Priority
?
1,501 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

604 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