Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
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
Old Apr 6th, 2008, 6:52 PM   #2
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 245
Rep Power: 1 Jabo is on a distinguished road
Re: writing a service in VB.NET

maybe download VB Express, for free, from Microsoft? They recently release the 2008 version so you may find what you're looking for there. It's free, so what have you got to lose really?
Jabo is offline   Reply With Quote
Old Apr 6th, 2008, 9:58 PM   #3
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
Re: writing a service in VB.NET

Only compatibility with the other programmers in the company - we have decided to remain on the 2003 edition of visual studio - at least for now - so I'm pretty stuck with that.

(I did download and install the c# freebie from Microsoft from VS 2008 - and it's pretty neat - but I'm not permitted to use that for code I have to check in. Alas.)
__________________
Ken -
New to PFO ... but been dabbling in various versions of BASIC since highschool - circa 1973.

"Shouldn't the 'Air and Space' museum be empty?" - Dennis Miller
opa6x57 is offline   Reply With Quote
Old Apr 6th, 2008, 11:42 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Re: writing a service in VB.NET

Is a complete rewrite necessary? You could wrap problematic bits in a C++ library project. It really depends on the "why" and "how much" of this rewrite effort.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Apr 7th, 2008, 12:31 AM   #5
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
Re: writing a service in VB.NET

Quote:
Originally Posted by Dameon View Post
Is a complete rewrite necessary? You could wrap problematic bits in a C++ library project. It really depends on the "why" and "how much" of this rewrite effort.
Hmmmmm - you ask a good question...

The department I currently program for - has had many programmers over the past several years. Each has brought his/her own unique strengths to the job.

Programs written during the tenure of Mr. A tended to be Gnu c++(g++). Written and compiled on various platforms - Linux/UNIX/Windows.

Programs written during the tenure of Mr. C tended to be ASP/ASP.NET.

Programs written during the tenure of Ms. D tended to be Gnu C (gcc). Written and compiled on LINUX platforms with libraries for Windows linked in when needed.

I am wanting to get all of these legacy programs updated into the Visual Studio language that's appropriate to each task - and appropriate to my own coding ability. And, in so doing - the code will be more maintainable. (There are only two programmers on staff that can really deal with this old/legacy c++ code. Everyone else is a .NET programmer of some kind. If I get this code into a mainstream source VB.NET, VC#, VC++ - then it will be more readily modifiable.

(I currently have 3 different versions of Gnu c++ compilers - and they don't co-exist very well - so I have them loaded on three different machines. For one of the applications - I have to use machine A ... for another application, Machine B, and so on...)

The bottom line - this function - the one I'm trying to get to work - I wrote a VC# project and this same function won't work from there, either.

I did not try this in VC++, though - I suppose I could.
__________________
Ken -
New to PFO ... but been dabbling in various versions of BASIC since highschool - circa 1973.

"Shouldn't the 'Air and Space' museum be empty?" - Dennis Miller
opa6x57 is offline   Reply With Quote
Old Apr 15th, 2008, 8:26 AM   #6
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 233
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Thumbs up Re: writing a service in VB.NET

Quote:
Originally Posted by opa6x57 View Post
(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. :-( )
as a matter of fact there is a process class in the 1.1 framework

check it out

http://msdn2.microsoft.com/en-us/lib...ss(VS.71).aspx


namespace it is under is system.diagnostics
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Reply

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 2:50 PM.

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