我们遇到了同一个问题,我能把应用程序写到服务里,但服务启动不起来,它报如下错误.
(1053 服务没有及时地响应启动或控制请求。)
原码如下:
Private Sub Command1_Click()keyvalue = 99
retvalue = RegCreateKey(HKEY_LOCAL_MACHINE, regkey, keyid)
retvalue = RegSetValueEx(keyid, "DisplayName", 0&, 1, ByVal keyvalue, Len(keyvalue) + 1)
retvalue = RegSetValueEx(keyid, "ImagePath", 0&, 2, ByVal keyvalue, Len(keyvalue) + 1)
retvalue = RegSetValueEx(keyid, "ObjectName", 0&, 1, ByVal keyvalue, Len(keyvalue) + 1)SetDWORDValue "HKEY_LOCAL_MACHINE\system\controlset002\services\report", "Start", "2"SetDWORDValue "HKEY_LOCAL_MACHINE\system\controlset002\services\report", "Type", "16"SetDWORDValue "HKEY_LOCAL_MACHINE\system\controlset002\services\report", "ErrorControl", "1"执行完后要改一下:
displayname 的健值为服务显示的名字ImagePath                 应用程序的路径
ObjectName                 登录方式(例如:LocalSystem)End Sub

解决方案 »

  1.   

    Sub gpvSetKeyDwordValue(ByVal plKey As Long, ByVal psKey As String, ByVal psSubKey As String, ByVal plKeyValue As Long)
    'ok
    '功    能:设置注册表中的双字值
    '参    数:
    '          输入:    plKey                   Long        根键名
    '                   psKey                   String      主键名
    '                   psSubKey                String      子键名
    '                   plKeyValue              Long        要设置双字值
    '          输出:    无
    '          影响:    glStatus                Long        状态值
        Dim llKeyID         As Long         '打开键的ID
        
        glStatus = ERROR_SUCCESS        '假设成功
        
        '确定参数有效
        If Len(psKey) = 0 Then      '主键未设置(子键未设置则读默认值)
            glStatus = REGAGENT_NOKEY
            Exit Sub
        End If
        
        '首先打开主键
        glStatus = RegOpenKey(plKey, psKey, llKeyID)
        
        If glStatus = ERROR_SUCCESS Then    '成功则设置值
            glStatus = RegSetValueEx(llKeyID, psSubKey, 0&, REG_DWORD, plKeyValue, Len(plKeyValue))
            glStatus = RegCloseKey(llKeyID)
        End If
        
    End SubPrivate Sub ParseKey(Keyname As String, Keyhandle As Long)
        
    rtn = InStr(Keyname, "\") 'return if "\" is contained in the KeynameIf Left(Keyname, 5) <> "HKEY_" Or Right(Keyname, 1) = "\" Then 'if the is a "\" at the end of the Keyname then
       MsgBox "Incorrect Format:" + Chr(10) + Chr(10) + Keyname 'display error to the user
       Exit Sub 'exit the procedure
    ElseIf rtn = 0 Then 'if the Keyname contains no "\"
       Keyhandle = GetMainKeyHandle(Keyname)
       Keyname = "" 'leave Keyname blank
    Else 'otherwise, Keyname contains "\"
       Keyhandle = GetMainKeyHandle(Left(Keyname, rtn - 1)) 'seperate the Keyname
       Keyname = Right(Keyname, Len(Keyname) - rtn)
    End IfEnd SubFunction GetMainKeyHandle(MainKeyName As String) As LongConst HKEY_CLASSES_ROOT = &H80000000
    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const HKEY_USERS = &H80000003
    Const HKEY_PERFORMANCE_DATA = &H80000004
    Const HKEY_CURRENT_CONFIG = &H80000005
    Const HKEY_DYN_DATA = &H80000006
       
    Select Case MainKeyName
           Case "HKEY_CLASSES_ROOT"
                GetMainKeyHandle = HKEY_CLASSES_ROOT
           Case "HKEY_CURRENT_USER"
                GetMainKeyHandle = HKEY_CURRENT_USER
           Case "HKEY_LOCAL_MACHINE"
                GetMainKeyHandle = HKEY_LOCAL_MACHINE
           Case "HKEY_USERS"
                GetMainKeyHandle = HKEY_USERS
           Case "HKEY_PERFORMANCE_DATA"
                GetMainKeyHandle = HKEY_PERFORMANCE_DATA
           Case "HKEY_CURRENT_CONFIG"
                GetMainKeyHandle = HKEY_CURRENT_CONFIG
           Case "HKEY_DYN_DATA"
                GetMainKeyHandle = HKEY_DYN_DATA
    End SelectEnd FunctionFunction SetDWORDValue(SubKey As String, Entry As String, Value As Long)Call ParseKey(SubKey, MainKeyHandle)If MainKeyHandle Then
       rtn = RegOpenKeyEx(MainKeyHandle, SubKey, 0, KEY_WRITE, hKey) 'open the key
       If rtn = ERROR_SUCCESS Then 'if the key was open successfully then
          rtn = RegSetValueExA(hKey, Entry, 0, REG_DWORD, Value, 4) 'write the value
          If Not rtn = ERROR_SUCCESS Then   'if there was an error writting the value
             If DisplayErrorMsg = True Then 'if the user want errors displayed
                MsgBox ErrorMsg(rtn)        'display the error
             End If
          End If
          rtn = RegCloseKey(hKey) 'close the key
       Else 'if there was an error opening the key
          If DisplayErrorMsg = True Then 'if the user want errors displayed
             MsgBox ErrorMsg(rtn) 'display the error
          End If
       End If
    End IfEnd Function
      

  2.   

    [email protected] ,我发个例程给你