Solved

Error 1607 when running VB EXE as NT service

Posted on 2004-08-08
9
592 Views
Last Modified: 2013-12-25
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
Comment
Question by:deandany
  • 5
  • 4
9 Comments
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11751173
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
 

Author Comment

by:deandany
ID: 11753566
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
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11753679
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
 

Author Comment

by:deandany
ID: 11779008
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:deandany
ID: 11791146
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
 
LVL 22

Accepted Solution

by:
DarkoLord earned 500 total points
ID: 11791604
Hmm try specifying "COMPUTERNAME\Username" as username...

Darko
0
 

Author Comment

by:deandany
ID: 11793462
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
 
LVL 22

Expert Comment

by:DarkoLord
ID: 11793798
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
 

Author Comment

by:deandany
ID: 11805147
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now