[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 620
  • Last Modified:

Error 1607 when running VB EXE as NT service

Hi all ,

following is the process

I have created an NT service thru VB and i have also started the service and stopped the service succesfully .

The problem is i want to do some operation after starting the service.

Actually i have a VB exe which accepts command line paramteres (among which one of them is the network drive to map) and accordingly maps network drive mentioned.

i want to run this EXE after starting the service ... and the command line paramters will be supplied by user in "SERVICES" window in "Administrative Tools" in control panel....

The user will run a VB app to create a service. then the will go to "Services" window and  select the service .. right click and start it physically and also give paramters ...

WHat happens is that when we start the service ... "error 1607 The process terminated unexpectedly"

i am using MS ocx file "NTVBsvc" lib file ..

i used 2 methods to map :

i use wscript.network to map drives
This runs as a service and maps .. but maps as "Disconnnected NetworkDrive (D:)"  ... and it also is not consistent with user name and password.

second method is wnetaddconnection2 . here the service tries to start mapping but stops throwing the above mentioned error

So what i did was , instead of calling an exe (which contains coding to map) after starting a service ... i did the mapping after the line which starts the service ...instead of calling a separate exe to do the same


But i am not able to do it ..  normal operations like "filecopy" and Writing to a text file can be done after connecting a service .. but not mapping


I think i have clearly stated the issue.. Can anyone help me out ??? its real crisis for me..


the sample source code basd on which i had done my coding is in the follwoing link

http://www.freevbcode.com/ShowCode.Asp?ID=4317

In this code ... In "Service " folder
Open "Service Sample.bas"

In "Main " module ...

        Do
*************************************
------> THIS IS WHERE MAPPING NEEDS TO BE DONE
*************************************
        Loop While WaitForSingleObject(hStopPendingEvent, 1000&) = WAIT_TIMEOUT

i think everthing is right out there ... so i am positive that some body will solve it ...

OS is XP / win 2K


-Dinesh


0
deandany
Asked:
deandany
  • 5
  • 4
1 Solution
 
DarkoLordCommented:
What about showing the windows' mapping dialog? It would also be easier to use that then specifying map path manually in service properties.. Here is the code:

Private Declare Function WNetConnectionDialog Lib "mpr" (ByVal hwnd As Long, ByVal dwType As Long) As Long
Private Const RESOURCETYPE_DISK = &H1

Public Sub ShowMapDialog()
    WNetConnectionDialog ByVal 0&, RESOURCETYPE_DISK
End Sub

There is also another, simpler way to map the network drive:
Shell "net use X: \\path_to_map\share", vbHide

Darko
0
 
deandanyAuthor Commented:
Hi  DarkoLord

Thanks for the reply .. but net use does not solve the purpose just bcos it does not accept login info.

And even WnetConnectDialog is not recommendable cos it will confuse the user. it should happen in the background.

Just stick to the VB code i have mentioned ... The main issue is mapping after running the service. Shell does not execute properly .

- Dinesh


 
0
 
DarkoLordCommented:
Okay I'll stick to your code, however it is possible to use username&pass with net use:

net use X: \\path_to_map\share /USER:administrator password

Darko
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
deandanyAuthor Commented:
hi darko

I have progressed a bit in my project.

I will narrow down my problem

now i am able to install a service, Start it , Stop it and uninstall it.

the only problem is that i have an exe which will execute when service is started ( the exe assigned in "Path of executable" in service window) .

this exe has coding to Map a drive using wnetaddconnection2 api . when i map without username and password.. i am able to map drives after starting service.

But the problem arises when i try passing valid username and password to Wnetaddconnection2 api

actually i am able to map using same user,pass word manulally

the error i am getting is error 1312 : the logon session has already been terminated

So i think there is some login issue cos of Windows setting etc and not in my mappin coding

i think this is helpful


0
 
deandanyAuthor Commented:
Hi

I encountered the following error when creating a service application using C#, Vb.net and installing it the service using Installutil.exe (in command prompt) with Service.Account as "User".
-----------------------------------------------------------------------An exception occurred during the Install phase.
System.ComponentModel.Win32Exception: The account name is invalid or does not ex
ist, or the password is invalid for the account name specified
-----------------------------------------------------------------------

I have created a User account with "Log on as service" privilage

still i get this error.

Any feedbacks?

-Dinesh

0
 
DarkoLordCommented:
Hmm try specifying "COMPUTERNAME\Username" as username...

Darko
0
 
deandanyAuthor Commented:
Great !!!! thanks for the timely help ....

But is there any workaround for this .. cos we cannot ask the user to give machine name ...

Anyways thanks buddy ... u earned these points

-Dinesh
0
 
DarkoLordCommented:
You're welcome... anyway try to use this function to get computer name:

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function fOSMachineName() As String

    Dim lngLen As Long, lngx As Long
    Dim strCompName As String
    lngLen = 16
    strCompName = String(lngLen, 0)
    lngx = GetComputerName(strCompName, lngLen)
    If lngx <> 0 Then
        fOSMachineName = Left(strCompName, lngLen)
    Else
        fOSMachineName = ""
    End If
End Function

Darko
0
 
deandanyAuthor Commented:
however i have one problem still

even though i am able to install a service , start it and stop it ... i am not able to map a network drive after starting the service ... i think Wnetaddconnection2 is not compatibel ..

or there could be one more issue ... i think the system user login is getting overlapped with the user login given to map to a network drive ...

Cos i am able to do everything else but to map a network drive after starting the service

Can anyone try this out and send me a piece of code that installs and starts an NT service and maps to a network drive with username and password .. (for now hard code the login info) ..

I need it to be done either in VB.net or C#.net ..

Use service.account = "User"

-Dinesh
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now