erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 Hello, I've noticed the updater isn't updating the files when the UAC is active because it gets blocked by it, to resolve this I need to get an UAC prompt up asking the user that the application needs more privileges.A bit like this:![](http://origin.arstechnica.com/journals/microsoft.media/uac-password.png)But I will I acomplish this in VB6, or is there another way of doing it?Thanks for reading. ![;)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/wink.png) Link to comment Share on other sites More sharing options...
abhi2011 Posted January 24, 2013 Share Posted January 24, 2013 I don't think this is possible because at the time of VB6 they might have never thought of vb6\. Only way of doing this might be running as an admin. Link to comment Share on other sites More sharing options...
MadalinV Posted January 24, 2013 Share Posted January 24, 2013 Why don't you disable UAC? It's annoying, when you work with many programs. Link to comment Share on other sites More sharing options...
abhi2011 Posted January 24, 2013 Share Posted January 24, 2013 He ain't talking about himself, he is talking about the end-users I believe. Link to comment Share on other sites More sharing options...
MadalinV Posted January 24, 2013 Share Posted January 24, 2013 but he could say them to disable the UAC, or try to do what this topic is about, to bypass it. Link to comment Share on other sites More sharing options...
abhi2011 Posted January 24, 2013 Share Posted January 24, 2013 The problem is that it cannot be bypasses. The only way would be ask them to disable it. Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 In order to elevate your process during run-time, you have to import "ShellExecuteEx" from shell32.dll and declare a structure that looks exactly like [this](http://msdn.microsoft.com/en-us/library/windows/desktop/bb759784%28v=vs.85%29.aspx). You will then have to set up that structure before calling the function, these are required to set up an elevated process:* Set lpVerb to "runas".* Set lpFile to the path of the executable (which can be found by using GetModuleFileName, which can be imported from kernel32.dll).You can then use this code to create new processes (http://stackoverflow.com/a/4762460):```Public Enum ShowConstants SW_HIDE = 0 SW_NORMAL = 1 SW_SHOWMINIMIZED = 2 SW_SHOWMAXIMIZED = 3 SW_SHOWNOACTIVATE = 4 SW_SHOW = 5 SW_MINIMIZE = 6 SW_SHOWMINNOACTIVE = 7 SW_SHOWNA = 8 SW_RESTORE = 9 SW_SHOWDEFAULT = 10End EnumPrivate Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String lpFile As String lpParameters As String lpDirectory As String nShow As Long hInstApp As Long lpIDList As Long lpClass As String hkeyClass As Long dwHotKey As Long hIcon As Long hProcess As LongEnd TypePrivate Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (pExecInfo As SHELLEXECUTEINFO) As LongPublic Function ExecuteProcess(ByVal FilePath As String, ByVal hwnd As Long, ByVal nShow As ShowConstants, Optional lpParameters As String = "", Optional LaunchElevated As Boolean = False) Dim ExecInfo As SHELLEXECUTEINFO On Error Goto Hell With ExecInfo ' Set up the structure. .cbSize = Len(ExecInfo) .fMask = .lpFile = FilePath .nShow = nShow .lpDirectory = ExtractDirectoryFromPath(FilePath) .lpParameters = lpParameters .hwnd = hwnd ' On Microsoft Windows Vista and later, one can use runas instead of Open, in order to execute the ' process as an elevated process. In that case, the user will be asked whether he or she wants to ' run the process as an administrator. If LaunchElevated = True Then .lpVerb = "runas" Else .lpVerb = "Open" End If End ExecInfo ExecuteProcess = ShellExecuteEx(ExecInfo) Exit FunctionHell: ExecuteProcess = FalseEnd FunctionPrivate Function ExtractDirectoryFromPath(Path As String) As String On Error Resume Next Dim Position As Long ' Find the right-most slash. Position = InStrRev(Path, "\") ' Extract everything on the left. ExtractDirectoryFromPath = Left$(Path, Position - 1)End Function```Additionally, you will have to check if the running process does have administrator rights, as you won'thave to elevate the process if it does. For this you will have to use AllocateAndInitializeSid, FreeSid and CheckTokenMembership which can all be imported from advapi32.dll (http://stackoverflow.com/a/4762460):```Private Const SECURITY_BUILTIN_DOMAIN_RID As Long = &H20Private Const DOMAIN_ALIAS_RID_ADMINS As Long = &H220Private Declare Function AllocateAndInitializeSid Lib "advapi32.dll" (pIdentifierAuthority As Any, ByVal nSubAuthorityCount As Byte, ByVal nSubAuthority0 As Long, ByVal nSubAuthority1 As Long, ByVal nSubAuthority2 As Long, ByVal nSubAuthority3 As Long, ByVal nSubAuthority4 As Long, ByVal nSubAuthority5 As Long, ByVal nSubAuthority6 As Long, ByVal nSubAuthority7 As Long, lpPSid As Long) As LongPrivate Declare Sub FreeSid Lib "advapi32.dll" (ByVal pSid As Long)Private Declare Function CheckTokenMembership Lib "advapi32.dll" (ByVal hToken As Long, ByVal pSidToCheck As Long, pbIsMember As Long) As LongPrivate Type SID_IDENTIFIER_AUTHORITY Value(0 To 5) As ByteEnd TypePrivate Function IsAdministrator() As Boolean Dim NtAuthority As SID_IDENTIFIER_AUTHORITY Dim pAdministratorGroup As Long Dim lResult As Long NtAuthority.Value(5) = 5 If AllocateAndInitializeSid(NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_AlIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, pAdministratorGroup) <> 0 Then If CheckTokenMembership(0, pAdministratorGroup, lResult) <> 0 Then IsAdministrator = (lResult <> 0) Exit Function End If Call FreeSid(pAdministratorGroup) End If IsAdministrator = FalseEnd Function```You can then use this code to elevate your own process:```Public Const MAX_PATH = 206Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" ( ByVal lpModuleName As String) As LongPrivate Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" ( ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As LongPublic Function SelfElevate() As Boolean Dim FilePath As String Dim hModule As Long Dim lResult As Long FilePath = Space$(MAX_PATH) hModule = GetModuleHandle(App.EXEName) lResult = GetModuleFileName(hModule, FilePath, MAX_PATH) If lResult = 0 Then SelfElevate = False Exit Function End If If IsAdministrator() Then SelfElevate = True Exit Function End If SelfElevate = ExecuteProcess(FilePath, 0, SW_NORMAL, "", True)End Function```Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 I've did everything you said, but now I get Run-time error 424: Object required on:```NtAuthory.Value(5) = 5``` Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 That's supposed to be NtAuthority.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 So without the .Value part? Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 No, NtAuthory is suppoed to be NtAuthority. Hence why you are getting run-time error 424: object required.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 Oh I'm sorry I didn't saw the difference. xDEDIT: So it did worked now but is this thesame as running a programm as admin, because when I run it as admin it also does it wrong. Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 > Oh I'm sorry I didn't saw the difference. xD> > EDIT: So it did worked now but is this thesame as running a programm as admin, because when I run it as admin it also does it wrong.Basically, it should ask the user whether he or she wants to run the programme as an administrator or not, because that's how UAC works.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 > Basically, it should ask the user whether he or she wants to run the programme as an administrator or not, because that's how UAC works.> > Yours faithfully,> > S.J.R. van Schaik.I know, it does ask it then, but it still doesn't correctly update the files then.I though doing it this way would make it do it correctly, but is that true? Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 > I know, it does ask it then, but it still doesn't correctly update the files then.> > I though doing it this way would make it do it correctly, but is that true?You might want to check what kind of errors you are getting when updating the files. As I can't be entirely sure whether the source of the problem is the lack of administrator rights or not. Although, in this specific case, it doesn't seem to be.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 The problem is that it does change the .ini with the version number in it, but not any other files that should be updated. (like the main .exe or graphics, etc.) Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 You'll want to look at your code that deals with writing the files, then. As there may be some errors that you haven't caught yet.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 I am used Joyce's Auto Updater, and I didn't changed anything to the writing to files part.I can upload the code of the updater and send it to you if you want. Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 I don't really have a VB6 editor installed, though.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 Well, I can send it to you in text if you want. Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 Hmm, you can send me the plain files, if you want. I can probably open them in vim. I just won't be able to really execute the code, though.Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 I've sended you the files. ![;)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/wink.png) Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 Where is your executable located (i.e. what is its path)?Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
erkro1 Posted January 24, 2013 Author Share Posted January 24, 2013 C:\Documents and Settings\Linda\Bureaublad\Engines\Yami's Auto-updater\Updater\Client Link to comment Share on other sites More sharing options...
Godlord Posted January 24, 2013 Share Posted January 24, 2013 Hmm, has it been able to download the RAR-file, and does it contain everything that is required? Also, are there are any errors being shown when updating?Yours faithfully,S.J.R. van Schaik. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now