New install NT service program almost done

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

New install NT service program almost done

Postby PhotonDemon » Fri Jan 21, 2011 8:46 am

Hi Everybody,

I am almost done with my new program to install Windows NT services. I will tell you more about it when it is ready and will post it here or probably on VA Smalltalk goodies. But I am having two small problems that maybe someone can help with.

I can't figure out how to set the Windows NT service description from my VA Smalltalk program. I can create the service and set all of what I consider important but not the description. I have gotten around this for now by using the Windows SC.Exe program. That, of course means you need to distribute the SC.Exe with your code when you want a customer to install your application.

The second problem is with using the -srvWorkingDir switch. If I set its value as a DOS short style path, the service starts and works just fine. If I set it as a quoted path with blanks, the service never finishes starting. It doesn't even time out and get a Windows error, it just keeps starting forever and it takes a reboot to clear things.

Using the short path isn't horrible but it would be nice to be able to see the long path from the Windows services window.

Does anyone else have this problem or am I messing something up? Is this a problem in abtntsrv.exe? Is it a short coming of what parameters you can pass to an NT service?

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: New install NT service program almost done

Postby marten » Fri Jan 21, 2011 9:18 am

I have not done this before (therefore its a guess), but I would go to http://msdn.microsoft.com/en-us/library/ms682006%28v=VS.85%29.aspx and look at the last example:

> OpenSCManager, OpenService API call is already defined within the image in the class OSScHandle
> define a new API call for ChangeServiceConfig2 function (definition is here http://msdn.microsoft.com/en-us/library/ms681988%28v=VS.85%29.aspx)

That's it ?

Marten


PhotonDemon wrote:Hi Everybody,

I can't figure out how to set the Windows NT service description from my VA Smalltalk program.
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: New install NT service program almost done

Postby PhotonDemon » Fri Jan 21, 2011 2:55 pm

Hi Marten,

Thanks, your the man :D

This is exactly what I need (at least it really look like it). I added ChangeServiceConfig2 to PlatformFunctions with the following:

Code: Select all
   PlatformFunctions at: 'ChangeServiceConfig2' ifAbsentPut: (PlatformFunction fromArray: #('C' 'ChangeServiceConfig2A' nil 'advapi32.dll' #(#pointer #uint32 #pointer) #bool)).


And I extended OSScHandle with the following:

Code: Select all
changeServiceConfig2: dwInfoLevel lpInfo: lpInfo
   "\C equivalent: BOOL ChangeServiceConfig2A(SC_HANDLE hService, DWORD dwInfoLevel, LPVOID lpInfo)."

   ^ChangeServiceConfig2 callWith: self with: dwInfoLevel with: lpInfo.


The only problem is, I am having a problem with the lpInfo value. It is a struct that I think should point to a string that is the new description. I think there are Smalltalk classes that could be used for this like OSCreatestruct or OSPtr and others but I'm not sure how to set it up. I don't know enough C to make the mental connection. Any help getting over this hump is greatly appreciated.

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: New install NT service program almost done

Postby benvandijk » Sat Jan 22, 2011 1:15 am

Hi Lou,

The structure you need is already defined in your image: class OSQueryServiceConfig.
We use this structure to obtain information about our NT - services.
According to the msdn links from Marten the same structure can be used to change the display name

The easiest way for you is to create and fill the structure using the QueryServiceConfig function,
fill the display name with your value and call the changeserviceConfig2 function.

This is the code you need for the queryservice call
Code: Select all
   | pcbBytesNeeded serviceHandle cbBufSize lpServiceConfig svcHandle |

   pcbBytesNeeded := AbtForeignOSObject new: 4.

   svcHandle := OSScHandle openSCManager: nil lpDatabaseName: nil dwDesiredAccess: 16r0F003F.

   serviceHandle := svcHandle openService: 'MyOwnService' dwDesiredAccess: 16r0F01FF.
   svcHandle closeServiceHandle.
   cbBufSize := 0.
   serviceHandle queryServiceConfig: nil cbBufSize: cbBufSize pcbBytesNeeded: pcbBytesNeeded.
   cbBufSize := pcbBytesNeeded uint32At: 0.
   OSQueryServiceConfig fixedSize: cbBufSize.
   lpServiceConfig := OSQueryServiceConfig new.
   serviceHandle
      queryServiceConfig: lpServiceConfig
      cbBufSize: cbBufSize
      pcbBytesNeeded: pcbBytesNeeded.

   serviceHandle closeServiceHandle.

   pcbBytesNeeded free.

   ^lpServiceConfig


On the other hand there is a method in Class OSScHandle

changeServiceConfig: dwServiceType
dwStartType: dwStartType
dwErrorControl: dwErrorControl
lpBinaryPathName: lpBinaryPathName
lpLoadOrderGroup: lpLoadOrderGroup
lpdwTagId: lpdwTagId
lpDependencies: lpDependencies
lpServiceStartName: lpServiceStartName
lpPassword: lpPassword
lpDisplayName: lpDisplayName

This might do the trick without using the structure

Greetz, Ben
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: New install NT service program almost done

Postby marten » Sat Jan 22, 2011 2:30 am

The display name is identical to the service description ?

Marten

benvandijk wrote:According to the msdn links from Marten the same structure can be used to change the display name
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: New install NT service program almost done

Postby benvandijk » Sat Jan 22, 2011 6:30 am

Hi marten and Lou,

I am sorry, i mixed up QueryServiceConfig and QueryServiceConfig2.

My example was based on QueryServiceConfig which has a different struct.

The service_description struct is defined in http://msdn.microsoft.com/en-us/library/ms685156%28v=vs.85%29.aspx

This looks like you need a pointer to a pointer pointing to a string containing the service description.

This is NOT the display name. It is the description field in the properties window.

The display name can be set when creating the service and changed using ChangeServiceConfig.

For a non-Microsoft and non-C programmer like me, it is not always easy to understand the msdn documentation :roll:

Greetz, Ben
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: New install NT service program almost done

Postby PhotonDemon » Sat Jan 22, 2011 8:30 am

Hi Marten & Ben,

Thanks for the help.

The service_description struct is defined in http://msdn.microsoft.com/en-us/library ... 85%29.aspx


I found this definition by following Marten's links.

This looks like you need a pointer to a pointer pointing to a string containing the service description.


I also came to this conclusion but I'm still not sure how to create the pointer to the pointer.

My latest attempt is shown below. It can be executed in a workspace. It runs without going boom but returns false from the #changeServiceConfig2:lpInfo: call and does not change the description.

There could be something wrong with my code that calls the DLL function but for now I think it is my construction of the pointer to the pointer.

Lou


Code: Select all
   | serviceName description ptr1 ptr2 scm service result |

   serviceName := 'KscTestNTService'.
   description := 'The new description.' asPSZ.
   ptr1 := OSPtr reference: description.
   ptr2 := OSPtr new: 4.
   ptr2 abtPointerAt: 0 put: ptr1.

"   Transcript cr; cr."

"      Create service."
   scm := OSScHandle openSCManager: nil lpDatabaseName: nil dwDesiredAccess: PlatformConstants::ServiceAllAccess.
   service := scm openService: serviceName dwDesiredAccess: PlatformConstants::ServiceChangeConfig.

   result := service changeServiceConfig2: 1 lpInfo: ptr2.

   result
      ifTrue: [Transcript show: 'Service Description Updated'; cr]
      ifFalse: [Transcript show: 'Service Description Update Failed'; cr].

   service closeServiceHandle; makeUndefined.
   scm closeServiceHandle; makeUndefined.

Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: New install NT service program almost done

Postby marten » Sat Jan 22, 2011 9:10 am

Code: Select all
| serviceName description ptr scm service result |

serviceName := 'Apache2.2'.
description := 'The new description.' copyToOSMemory.

ptr := OSObjectPointer new: 1 itemType: OSStringZ.      
ptr at: 0 put: description.
       
" Create service."
scm := OSScHandle openSCManager: nil lpDatabaseName: nil dwDesiredAccess: PlatformConstants::ScManagerAllAccess.
scm isNull
   ifTrue:[   self halt ]
   ifFalse:[
      service := scm openService: serviceName asPSZ dwDesiredAccess: PlatformConstants::ServiceChangeConfig.
      service isNull
         ifTrue:[
                          self halt            
         ]
         ifFalse:[
            result := service changeServiceConfig2: 1 lpInfo: ptr.
            result
                ifTrue: [Transcript show: 'Service Description Updated'; cr]
                ifFalse: [Transcript show: 'Service Description Update Failed'; cr].
            service closeServiceHandle; makeUndefined.
      ].
       scm closeServiceHandle; makeUndefined.
].
"to free memory again ..."
description free


... and please send Instantiations an EMail, that they should add the missing win32 definitions .... and this code needs special access rights (administrator)
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: New install NT service program almost done

Postby PhotonDemon » Sat Jan 22, 2011 1:27 pm

Hey Marten,

Excellent, as I said, you are the man :wink:

This allows me to completely install an NT service without the use of the SC.Exe program. It is getting late, so I will work on the program some more tomorrow or Monday. It won't take much to replace the SC.Exe call with this code.

Now I just need to solve the problem with needing to use DOS short style path with the -srvWorkingDir switch.

If Instantiations doesn't pick up this post, I will email them about the win32 definitions. Thanks again :)

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm

Re: New install NT service program almost done

Postby marten » Sun Jan 23, 2011 10:57 pm

Perhaps you could summarize, what you have done and how the whole process is done ...

Thanks,

Marten

PhotonDemon wrote:
If Instantiations doesn't pick up this post, I will email them about the win32 definitions.

Lou
Marten Feldtmann, Principal Smalltalk User, Private
SkypeMe callto://marten.feldtmann
marten
[|]
 
Posts: 641
Joined: Sat Oct 14, 2006 7:10 am
Location: Hamburg - Germany

Re: New install NT service program almost done

Postby PhotonDemon » Mon Jan 24, 2011 6:45 am

Hi Marten,

Perhaps you could summarize, what you have done and how the whole process is done ...


I will. I have a some more tweaking to do, to make the program a little more general than my specific needs and I want to add some simple help info. Then I will write a readme file to give a big picture view of what the program does. And maybe something else that explains the process and OS calls a little.

Lou
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
PhotonDemon
[|]
 
Posts: 176
Joined: Thu Dec 20, 2007 1:45 pm


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest

cron