开机自动运行的Option Explicit Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long Const REG_SZ = 1 Const HKEY_LOCAL_MACHINE = &H80000002Private Sub Command1_Click() 'RegCreateKey "hkey_local_machine\software\microsoft\windows\currentversion\run", "aaa", 1 Dim application As String Dim filename As String application = "我的测试软件" filename = "c:\mysoft\www.exe" Call SaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", application, filename) End Sub Public Sub SaveString(Hkey As Long, strPath As String, strValue As String, strdata As String) Dim KeyHand As Long Dim r As Longr = RegCreateKey(Hkey, strPath, KeyHand) r = RegSetValueEx(KeyHand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata)) r = RegCloseKey(KeyHand)End Sub
如何获得当前Windows登录的用户名? '声明: Private Declare Function GetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _ As Long '使用代码如下: Private Sub Form_Load() Dim s As String,cnt As Long ,dl As Long,CurUser As String cnt = 199 s = String$(200, 0) dl = GetUserName(s, cnt) Debug.Print(dl <> 0,"当前用户=" & Left$(s,cnt),"当前用户=") End Sub
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Const REG_SZ = 1
Const HKEY_LOCAL_MACHINE = &H80000002Private Sub Command1_Click()
'RegCreateKey "hkey_local_machine\software\microsoft\windows\currentversion\run", "aaa", 1
Dim application As String
Dim filename As String
application = "我的测试软件"
filename = "c:\mysoft\www.exe"
Call SaveString(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Run", application, filename)
End Sub
Public Sub SaveString(Hkey As Long, strPath As String, strValue As String, strdata As String)
Dim KeyHand As Long
Dim r As Longr = RegCreateKey(Hkey, strPath, KeyHand)
r = RegSetValueEx(KeyHand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
r = RegCloseKey(KeyHand)End Sub
'声明:
Private Declare Function GetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _ As Long
'使用代码如下:
Private Sub Form_Load()
Dim s As String,cnt As Long ,dl As Long,CurUser As String cnt = 199
s = String$(200, 0)
dl = GetUserName(s, cnt)
Debug.Print(dl <> 0,"当前用户=" & Left$(s,cnt),"当前用户=")
End Sub
RegDeleteValueA
RegEnumValueA
RegFlushKey
RegOpenKeyExA
RegQueryValueExA
RegSetValueExA
RegCloseKey
RegCreateKeyExA
RegCreateKeyA
RegDeleteKeyA
RegEnumKeyA
RegEnumKeyExA
RegOpenKeyA
RegQueryValueA
RegSetValueA
RegQueryInfoKeyA
GetUserNameA
RegNotifyChangeKeyValue
RegLoadKeyA
RegUnLoadKeyA
RegSaveKeyA
RegReplaceKeyA
RegQueryMultipleValuesA
RegRemapPreDefKey
RegConnectRegistryA
CancelOverlappedAccess
GetEffectiveRightsFromAclA
GetEffectiveRightsFromAclW
GetExplicitEntriesFromAclA
GetExplicitEntriesFromAclW
RegRestoreKeyA
RegSetKeySecurity
GetAuditedPermissionsFromAclA
GetAuditedPermissionsFromAclW
GetOverlappedAccessResults
RegGetKeySecurity
SetEntriesInAclA
SetEntriesInAclW
ConvertAccessToSecurityDescriptorA
ConvertAccessToSecurityDescriptorW
SetEntriesInAccessListA
SetEntriesInAccessListW
SetEntriesInAuditListA
SetEntriesInAuditListW
TrusteeAccessToObjectA
TrusteeAccessToObjectW
ConvertSecurityDescriptorToAccessA
ConvertSecurityDescriptorToAccessNamedA
ConvertSecurityDescriptorToAccessNamedW
ConvertSecurityDescriptorToAccessW
LookupSecurityDescriptorPartsA
LookupSecurityDescriptorPartsW
SetNamedSecurityInfoA
SetNamedSecurityInfoW
SetSecurityInfo
GetNamedSecurityInfoA
GetNamedSecurityInfoW
GetSecurityInfo
BuildSecurityDescriptorA
BuildSecurityDescriptorW
GetAccessPermissionsForObjectA
GetAccessPermissionsForObjectW
GetNamedSecurityInfoExA
GetNamedSecurityInfoExW
GetSecurityInfoExA
GetSecurityInfoExW
SetNamedSecurityInfoExA
SetNamedSecurityInfoExW
SetSecurityInfoExA
SetSecurityInfoExW
RevertToSelf
AbortSystemShutdownA
AbortSystemShutdownW
AllocateLocallyUniqueId
CloseEventLog
CloseServiceHandle
DeleteService
DeregisterEventSource
DestroyPrivateObjectSecurity
FreeSid
GetCurrentHwProfileA
GetCurrentHwProfileW
GetLengthSid
GetMultipleTrusteeA
GetMultipleTrusteeOperationA
GetMultipleTrusteeOperationW
GetMultipleTrusteeW
GetSecurityDescriptorLength
GetSidIdentifierAuthority
GetSidLengthRequired
GetSidSubAuthorityCount
GetTrusteeNameA
GetTrusteeNameW
GetTrusteeTypeA
GetTrusteeTypeW
ImpersonateLoggedOnUser
ImpersonateNamedPipeClient
ImpersonateSelf
IsValidAcl
IsValidSid
LockServiceDatabase
NotifyBootConfigStatus
StartServiceCtrlDispatcherA
StartServiceCtrlDispatcherW
UnlockServiceDatabase
IsValidSecurityDescriptor
AreAllAccessesGranted
AreAnyAccessesGranted
BackupEventLogA
BackupEventLogW
BuildImpersonateTrusteeA
BuildImpersonateTrusteeW
BuildTrusteeWithNameA
BuildTrusteeWithNameW
BuildTrusteeWithSidA
BuildTrusteeWithSidW
ClearEventLogA
ClearEventLogW
DeleteAce
EqualPrefixSid
EqualSid
FindFirstFreeAce
GetNumberOfEventLogRecords
GetOldestEventLogRecord
GetSidSubAuthority
GetUserNameW
MapGenericMask
NotifyChangeEventLog
OpenBackupEventLogA
OpenBackupEventLogW
OpenEventLogA
OpenEventLogW
QueryServiceStatus
RegDeleteKeyW
RegDeleteValueW
RegUnLoadKeyW
RegisterEventSourceA
RegisterEventSourceW
RegisterServiceCtrlHandlerA
RegisterServiceCtrlHandlerW
SetServiceStatus
SetThreadToken
InitializeSecurityDescriptor
ControlService
CopySid
DuplicateToken
GetAce
GetSecurityDescriptorControl
GetSecurityDescriptorGroup
GetSecurityDescriptorOwner
InitializeAcl
InitializeSid
IsTextUnicode
LookupPrivilegeValueA
LookupPrivilegeValueW
MakeSelfRelativeSD
ObjectCloseAuditAlarmA
ObjectCloseAuditAlarmW
ObjectDeleteAuditAlarmA
ObjectDeleteAuditAlarmW
OpenProcessToken
OpenSCManagerA
OpenSCManagerW
OpenServiceA
OpenServiceW
PrivilegeCheck
RegConnectRegistryW
RegCreateKeyW
RegLoadKeyW
RegOpenKeyW
RegRestoreKeyW
RegSaveKeyW
SetFileSecurityA
SetFileSecurityW
SetKernelObjectSecurity
SetServiceObjectSecurity
StartServiceA
StartServiceW
SetSecurityDescriptorGroup
SetSecurityDescriptorOwner
AddAccessAllowedAce
AddAccessDeniedAce
GetAclInformation
GetSecurityDescriptorDacl
GetSecurityDescriptorSacl
GetServiceDisplayNameA
GetServiceDisplayNameW
GetServiceKeyNameA
GetServiceKeyNameW
LookupPrivilegeNameA
LookupPrivilegeNameW
OpenThreadToken
QueryServiceConfigA
QueryServiceConfigW
QueryServiceLockStatusA
QueryServiceLockStatusW
RegEnumKeyW
RegQueryValueW
RegReplaceKeyW
SetAclInformation
SetServiceBits
SetTokenInformation
SetSecurityDescriptorDacl
SetSecurityDescriptorSacl
AddAce
BuildExplicitAccessWithNameA
BuildExplicitAccessWithNameW
GetFileSecurityA
GetFileSecurityW
GetKernelObjectSecurity
GetPrivateObjectSecurity
GetTokenInformation
InitiateSystemShutdownA
InitiateSystemShutdownW
LookupPrivilegeDisplayNameA
LookupPrivilegeDisplayNameW
PrivilegedServiceAuditAlarmA
PrivilegedServiceAuditAlarmW
QueryServiceObjectSecurity
RegOpenKeyExW
RegQueryMultipleValuesW
RegSetValueW
SetPrivateObjectSecurity
AddAuditAccessAce
AdjustTokenGroups
AdjustTokenPrivileges
BuildImpersonateExplicitAccessWithNameA
BuildImpersonateExplicitAccessWithNameW
CreatePrivateObjectSecurity
DuplicateTokenEx
EnumDependentServicesA
EnumDependentServicesW
LogonUserA
LogonUserW
ObjectPrivilegeAuditAlarmA
ObjectPrivilegeAuditAlarmW
RegQueryValueExW
RegSetValueExW
LookupAccountNameA
LookupAccountNameW
LookupAccountSidA
LookupAccountSidW
ReadEventLogA
ReadEventLogW
AccessCheck
EnumServicesStatusA
EnumServicesStatusW
RegEnumKeyExW
RegEnumValueW
RegCreateKeyExW
ReportEventA
ReportEventW
AccessCheckAndAuditAlarmA
AccessCheckAndAuditAlarmW
AllocateAndInitializeSid
ChangeServiceConfigA
ChangeServiceConfigW
CreateProcessAsUserA
CreateProcessAsUserW
MakeAbsoluteSD
ObjectOpenAuditAlarmA
ObjectOpenAuditAlarmW
RegQueryInfoKeyW
CreateServiceA
CreateServiceW
CryptAcquireContextW
CryptAcquireContextA
CryptContextAddRef
CryptReleaseContext
CryptGenKey
CryptDuplicateKey
CryptDeriveKey
CryptDestroyKey
CryptSetKeyParam
CryptGetKeyParam
CryptGenRandom
CryptGetUserKey
CryptExportKey
CryptImportKey
CryptEncrypt
CryptDecrypt
CryptCreateHash
CryptDuplicateHash
CryptHashData
CryptHashSessionKey
CryptDestroyHash
CryptSignHashW
CryptSignHashA
CryptVerifySignatureW
CryptVerifySignatureA
CryptSetProvParam
CryptGetProvParam
CryptSetHashParam
CryptGetHashParam
CryptSetProviderW
CryptSetProviderA
CryptSetProviderExW
CryptSetProviderExA
CryptGetDefaultProviderW
CryptGetDefaultProviderA
CryptEnumProviderTypesW
CryptEnumProviderTypesA
CryptEnumProvidersW
CryptEnumProvidersA