-
Oct 19th, 2017, 09:09 PM
#1
Thread Starter
Lively Member
register control before using it in project
Hi, im writing updates to demo game which uses .ocx control and aditional .dll's. have made this this way:
Code:
Option Explicit
Private Declare Function SetCurrentDirectory Lib "kernel32" _
Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim OSBits
Dim sSave As String, Ret As Long
Private Sub Form_Load()
sSave = Space(255)
Ret = GetSystemDirectory(sSave, 255)
sSave = Trim(Left$(sSave, Ret - 9))
OSBits = IIf(Len(Environ$("PROGRAMFILES(X86)")) > 0, 64, 32)
'SetCurrentDirectory App.path + "\library1"
If OSBits = 64 Then
CopyFiles App.path & "\library1", sSave + "\syswow64"
On Error Resume Next
SetCurrentDirectory sSave + "\syswow64"
ShellExecute 0, "runas", "regsvr32", "dx7vb.dll /s", vbNullString, 1
ShellExecute 0, "runas", "regsvr32", "rmcontrol.ocx /s", vbNullString, 1
End If
If OSBits = 32 Then
On Error Resume Next
CopyFiles App.path & "\library1", sSave + "\System32"
SetCurrentDirectory sSave + "\System32"
MRRegisterLibrary "dx7vb.dll /s"
MRRegisterLibrary "rmcontrol.ocx /s"
End If
Timer1.Enabled = True
End Sub
Public Function MRRegisterLibrary(path$)
Shell "Regsvr32.exe " & path$, vbHide
End Function
Private Sub Timer1_Timer()
SetCurrentDirectory App.path
Shell App.path + "\library2\game.exe"
End
End Sub
Public Function CopyFiles(ByRef strSource As String, ByRef strDestination As String)
On Error Resume Next
Dim objfso
Set objfso = CreateObject("Scripting.FileSystemObject")
Dim strFile As String
If Right$(strSource, 1) <> "\" Then strSource = strSource & "\"
If Right$(strDestination, 1) <> "\" Then strDestination = strDestination & "\"
strFile = Dir(strSource & "*.*")
Do While Len(strFile)
With objfso
If Not .FolderExists(strDestination) Then .CreateFolder (strDestination)
.CopyFile strSource & strFile, strDestination & strFile
End With
strFile = Dir
Loop
Set objfso = Nothing
Exit Function
End Function
added also manifest to executable to be sure,
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
i am still not persuaded if it solved opening with components:/
anyone can have sugestions?
Last edited by Krzysztof#; Oct 20th, 2017 at 04:40 AM.
-
Oct 19th, 2017, 11:43 PM
#2
Re: register control before using it in project
This is very unsafe for numerous reasons.
An installer is supposed to check to see if an ActiveX library (OCX or DLL) has already been installed. If so, then it should just use it, if not then it should place the file into the location defined within the corresponding .DEP file provided by the author and then register the library. For this process to succeed without problems the installer must run with elevated privileges.
If you try to have your program do this there are hazards. One is that if it runs as a standard user dropping such a file and registering it are both likely to fail since protected locations are generally involved. If you have no Vista-aware manifest the failure will be intercepted and virtualized and Windows will let your program proceed. From there it may work or this may cause additional headaches now or down the road, for other programs as well as yours. If you do have such a manifest you will get an error 70 or something similar.
One way around this involves far more complex manifests, forming private assemblies with activation context information. Only then is it safe for your program to have private copies of such ActiveX libraries and use them without elevated registration.
You don't need any SetCurrentDirectory API call. The VB ChDir statement does this.
-
Oct 20th, 2017, 03:17 AM
#3
Thread Starter
Lively Member
Re: register control before using it in project
You don't need any SetCurrentDirectory API call. The VB ChDir statement does this.
Great, thanks
You are right, i get 'copy oryginal files' message in windows xp, windows 10 icons are with administrator privileges but still not all files are copied with first run. windows 7 at start also shows Attachment 152939
Other than Package & Deployment Wizard or Inno Setup Compiler what other installers may be good for this?
Last edited by Krzysztof#; Oct 21st, 2017 at 11:37 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|