Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 6th, 2008, 1:14 PM   #1
opa6x57
Hmmmm ... Is there more??
 
opa6x57's Avatar
 
Join Date: Apr 2008
Location: Post Falls, ID
Posts: 15
Rep Power: 0 opa6x57 is on a distinguished road
writing a service in VB.NET

I have an existing c++ (actually, g++) program that registers as a service - and then - while running - reacts to the presence of a text file. Depending on the content of the lines in the text file - the service will do one of two things:

1) start a new process - running a batch file created by the internet user via an ASP page.

--Or--
2) send a small TCP/IP packet to a UNIX machine which has a companion daemon listening for the imcoming packet.

I'm trying to port this existing code to VB.NET.

The two winapi functions that the existing service uses are these:

if (LogonUser((LPTSTR)UserName, (LPTSTR)Domain, (LPTSTR)Passwd, 
LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, &hUserHandle)) {
--and--
if (CreateProcessAsUser(hUserHandle, NULL, (CHAR*)line.c_str(),
 NULL, NULL, FALSE, (DWORD)NULL, NULL, NULL, &si, &pi)) {

The problem is - I cannot get the second function to work in VB.NET - I've tried just about every variation on this system call - searched the web for examples - and haven't found anything that will get this last function to work.

Here's one example of the VB function declaration and the call that I've tried. To no avail.

Public Declare Auto Function CreateProcessAsUser Lib "advapi32.dll" ( _
    ByVal hToken As IntPtr, _
    ByVal strApplicationName As String, _
    ByVal strCommandLine As String, _
    ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, _
    ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
    ByVal bInheritHandles As Boolean, _
    ByVal dwCreationFlags As Integer, _
    ByVal lpEnvironment As IntPtr, _
    ByVal lpCurrentDriectory As String, _
    ByRef lpStartupInfo As STARTUPINFO, _
    ByRef lpProcessInformation As PROCESS_INFORMATION) As Boolean

Public Structure SECURITY_ATTRIBUTES
    Public nLength As Integer
    Public lpSecurityDescriptor As IntPtr
    Public bInheritHandle As Boolean
End Structure

Public Structure PROCESS_INFORMATION
    Public hProcess As IntPtr
    Public hThread As IntPtr
    Public dwProcessId As Integer
    Public dwThreadId As Integer
End Structure

Public Structure STARTUPINFO
    Public cb As Integer
    Public lpReserved As IntPtr
    Public lpDesktop As IntPtr
    Public lpTitle As IntPtr
    Public dwX As Integer
    Public dwY As Integer
    Public dwXSize As Integer
    Public dwYSize As Integer
    Public dwXCountChars As Integer
    Public dwYCountChars As Integer
    Public dwFillAttribute As Integer
    Public dwFlags As Integer
    Public wShowWindow As Short
    Public cbReserved2 As Short
    Public lpReserved2 As IntPtr
    Public hStdInput As IntPtr
    Public hStdOutput As IntPtr
    Public hStdError As IntPtr
End Structure
Then - in the sub main...
Dim saProc As SECURITY_ATTRIBUTES = New SECURITY_ATTRIBUTES
Dim saThread As SECURITY_ATTRIBUTES = New SECURITY_ATTRIBUTES
saProc.nLength = Marshal.SizeOf(saProc)
saProc.lpSecurityDescriptor = IntPtr.Zero
saThread.nLength = Marshal.SizeOf(saThread)
saThread.lpSecurityDescriptor = IntPtr.Zero
If CreateProcessAsUser( _
    hToken, _
    String.Empty, _
    strCmdLine, _
    saProc, _
    saThread, _
    False, _
    0, _
    IntPtr.Zero, _
    String.Empty, _
    si, _
    pi) Then

(We're still using vb.net from VS 2003 - so the new 'process class' that came out with the 2.0 framework isn't available to me for this project. :-( )
opa6x57 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net to VBScript randum77 JavaScript and Client-Side Browser Scripting 3 May 1st, 2007 3:39 PM
difference VB and VB.net gpreetsingh Visual Basic .NET 10 Feb 18th, 2006 6:18 AM
vb6 to vb.net bl00dninja Visual Basic .NET 2 Sep 24th, 2005 1:55 PM
Making a database application in VB.NET emdiesse Visual Basic .NET 3 Sep 18th, 2005 5:58 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC