Solved

Error 1607 when running VB EXE as NT service

Posted on 2004-08-08
9
589 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:deandany
Comment Utility
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
Comment Utility
Hmm try specifying "COMPUTERNAME\Username" as username...

Darko
0
 

Author Comment

by:deandany
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

10 Experts available now in Live!

Get 1:1 Help Now