March 28, 2024, 04:17:06 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Run your program as Administrator

Started by Andy, June 01, 2016, 06:29:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

June 01, 2016, 06:29:44 AM Last Edit: June 01, 2016, 06:46:07 AM by Andy
Here is my example of how to make your exe file run as an Administrator.

How to:

1. Setup - you can run setup_stringmap.exe - just browse to your IWBDev / EBasic root folder in C:\Program Files and click OK.

Alternatively, if that doesn't work, copy the .lib file to your Libs folder, the .inc file to your include folder.

2. Compile regviewer.iwb and run it.

If asked if you want to allow this program to run, obviously click 'yes'.

3. Navigate to HKEY_USERS
4. You will see registry keys like S-1-5-18, or 19 etc.
5. Click on one of these to open

If it opens, the regviewer.exe has been elevated to admin level and you will see the sub keys listed.

If it doesn't work, the program will freeze.

Bottom line - you can add / amend the following code in your own program



$include "windowssdk.inc"
$include "commctrl.inc"
$IncluDE "StringMap.inc"

'====================================================
'                                                   '
' This code to run this program as an Administrator '
'                                                   '
'====================================================

string MyProgram = "regviewer.exe" 'Name of this exe to run as admin.

string RAS2 = ""
RAS2 = ltrim$(SMRegGetValue("HKEY_CURRENT_USER\\Software\\StringMap","RunAsAdminDone"))

if RAS2 = "1"
  SMRegDeleteValue("HKEY_CURRENT_USER\\Software\\StringMap","RunAsAdmin")
  SMRegDeleteValue("HKEY_CURRENT_USER\\Software\\StringMap","RunAsAdminDone")
  SMRegDeleteKey("HKEY_CURRENT_USER\\Software\\StringMap")
else
  SMRegSetValue("HKEY_CURRENT_USER\\Software\\StringMap",getstartpath + MyProgram,"RunAsAdmin")
  SMEndStringMap()
  system getstartpath + "RunAsAdmin.exe"
  end
endif

'============================
'                           '
' End of Administrator code '
'                           '
'============================


By changing the string "MyProgram" to your own .exe name of your code.

Note - you need the runasadmin.exe and your own exe in the same folder, but you could change that if you wish.

There are other ways to do this, but I think you might like this.

BTW - Regviewer now reads / writes qwords up to and including FFFFFFFFFFFFFFFF (16 F's).

Not bad at 50 today!

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.