Hi,
I have some code that somebody has vritten in C and although I have got it to roughly work it is hard going and I can't get it to do exactly what I want as I know even less about c than I do about VB :)
I have chopped the code a bit so I hope it makes enough sense, what I am trying to do is load a remote registry in from a server , make some changes and then unload it.later.
I have google'd quite a bit but I can only find C or VB6 code for this and I cannot get it to work properly in VB .NET -
-
[StructLayout(LayoutKind.Sequential)]
-
public struct LUID
-
{
-
public int LowPart;
-
public int HighPart;
-
}
-
[StructLayout(LayoutKind.Sequential)]
-
public struct TOKEN_PRIVILEGES
-
{
-
public LUID Luid;
-
public int Attributes;
-
public int PrivilegeCount;
-
}
-
-
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
-
public static extern int OpenProcessToken(int ProcessHandle, int DesiredAccess,
-
ref int tokenhandle);
-
-
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
-
public static extern int GetCurrentProcess();
-
-
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
-
public static extern int LookupPrivilegeValue(string lpsystemname, string lpname,
-
[MarshalAs(UnmanagedType.Struct)] ref LUID lpLuid);
-
-
[DllImport("advapi32.dll", CharSet = CharSet.Auto)]
-
public static extern int AdjustTokenPrivileges(int tokenhandle, int disableprivs,
-
[MarshalAs(UnmanagedType.Struct)]ref TOKEN_PRIVILEGES Newstate, int bufferlength,
-
int PreivousState, int Returnlength);
-
-
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
-
public static extern int RegLoadKey(uint hKey, string lpSubKey, string lpFile);
-
-
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
-
public static extern int RegUnLoadKey(uint hKey, string lpSubKey);
-
-
public const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
-
public const int TOKEN_QUERY = 0x00000008;
-
public const int SE_PRIVILEGE_ENABLED = 0x00000002;
-
public const string SE_RESTORE_NAME = "SeRestorePrivilege";
-
public const string SE_BACKUP_NAME = "SeBackupPrivilege";
-
public const uint HKEY_USERS = 0x80000003;
-
public string shortname;
-
-
-
-
-
[StructLayout(LayoutKind.Sequential)]
-
-
-
private void Registry_Hive_Load (object sender, EventArgs e)
-
{
-
-
try
-
{
-
int token = 0;
-
int retval = 0;
-
-
-
TOKEN_PRIVILEGES TP = new TOKEN_PRIVILEGES();
-
TOKEN_PRIVILEGES TP2 = new TOKEN_PRIVILEGES();
-
LUID RestoreLuid = new LUID();
-
LUID BackupLuid = new LUID();
-
-
retval = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token);
-
retval = LookupPrivilegeValue(null, SE_RESTORE_NAME, ref RestoreLuid);
-
retval = LookupPrivilegeValue(null, SE_BACKUP_NAME, ref BackupLuid);
-
TP.PrivilegeCount = 1;
-
TP.Attributes = SE_PRIVILEGE_ENABLED;
-
TP.Luid = RestoreLuid;
-
TP2.PrivilegeCount = 1;
-
TP2.Attributes = SE_PRIVILEGE_ENABLED;
-
TP2.Luid = BackupLuid;
-
-
retval = AdjustTokenPrivileges(token, 0, ref TP, 1024, 0, 0);
-
retval = AdjustTokenPrivileges(token, 0, ref TP2, 1024, 0, 0);
-
-
-
if (RegLoadKey(HKEY_USERS, "Tempload", label2.Text) == 0)
-
{
-
-
profileloaded = true;
-
richTextBox1.AppendText("Profile Loaded"+"\n");
-
}
-
}
-
-
4 2023
no replies yet so I have started to try and convert the code but am completely stuck with 'OpenProcessToken' , i've Tried everyting and spent ages on google but keep on getting Error 998 which I checked and is ERROR_NOACCESS when I check the last dll error although the c# code works fine, can anybody help please -
Public Declare Function OpenProcessToken Lib "advapi32.dll" _ (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _ ByVal TokenHandle As Long) As Long
-
-
Private Const TOKEN_ADJUST_PRIVLEGES = &H20
-
Private Const TOKEN_QUERY = &H8
-
Private Const SE_PRIVILEGE_ENABLED = &H2
-
-
MyToken = 0
-
Retval = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVLEGES Or TOKEN_QUERY, MyToken)
-
-
MsgBox("OpenProcess: " & Err.LastDllError)
-
HI,
Your problem' solution is in "developerfusion.com"...
Your problem will be solved deffinetely....
-malav.
no replies yet so I have started to try and convert the code but am completely stuck with 'OpenProcessToken' , i've Tried everyting and spent ages on google but keep on getting Error 998 which I checked and is ERROR_NOACCESS when I check the last dll error although the c# code works fine, can anybody help please -
Public Declare Function OpenProcessToken Lib "advapi32.dll" _ (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _ ByVal TokenHandle As Long) As Long
-
-
Private Const TOKEN_ADJUST_PRIVLEGES = &H20
-
Private Const TOKEN_QUERY = &H8
-
Private Const SE_PRIVILEGE_ENABLED = &H2
-
-
MyToken = 0
-
Retval = OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVLEGES Or TOKEN_QUERY, MyToken)
-
-
MsgBox("OpenProcess: " & Err.LastDllError)
-
see here for conversion of your code... http://labs.developerfusion.co.uk/co...to-csharp.aspx
see here for conversion of your code... http://labs.developerfusion.co.uk/co...to-csharp.aspx
I will have to keep hold of the URL for that site but unfortunately it has some issues converting the code to import DLL's but I might be able to work round that so will have to try later when I have time.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
Hi,
In a nutshell, why am I getting the results I am getting? I would have
expected a call to method1( n) to return an 'n' length string.
At first I thought it was a problem in my function,...
|
by: Skybuck Flying |
last post by:
Hi,
This is a somewhat cleaned up version 0.02 of the nrand48() routine.
There are still a few issues:
This code needs brackets but where ?
X = (uint64) xsubi << 32 | (uint32) xsubi << 16...
|
by: andy.mcvicker |
last post by:
Hi Gang
I'm not sure what needs to be changed when converting an asp to vbs.
I'm not sure if I can with my code below. Can someone PLEASE convert
the text below to vbs?
Thanks a million....
|
by: shapper |
last post by:
Hello,
I am trying to convert an Asp.Net XML sitemap file in a Google XMl
sitemap file using a XSL file using an HttpHandler.
Everything seems well in my code but I am getting an error:
XML...
|
by: bbawa1 |
last post by:
It says invalid expression term &&
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if...
|
by: Lynn |
last post by:
Hello,
I have a website that is working fine. I have just turned on "option strict"
and am getting an error with the parts of my code. I have fixed everything
but this section, which has me...
|
by: cool.vimalsmail |
last post by:
i dont know how to convert a txt file into a zip file
(i.e.,)i have a file named packages and i want the packages file with
a ".gz" extension by implementing a python program
|
by: Sunfire |
last post by:
Can somebody put this code into c#?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim imageFolder As String
Dim imageText As String
Dim bm As...
|
by: ahilar12 |
last post by:
1. <head>
2. <script type="text/javascript">
3. </script>
4. </head>
5. <body>
6. <form>
7. <select name="team" id="mylist" >
8. <option></option>
9....
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |