Win32::Lanman - implements MS Lanmanager functions
use Win32::Lanman;
This module implements the MS Lanmanager functions
Documentation for use and meaning of the Constants can be found at http://search.microsoft.com/us/dev/default.asp
SERVICE_CONTROL_DESCRIPTIONS
SERVICE_STATE_DESCRIPTIONS
SERVICE_CONTROLS
SERVICE_START_TYPES
SERVICE_ERROR_TYPES
SERVICE_ACCEPTED_CONTROLS
SERVICE_ADAPTER
SERVICE_RECOGNIZER_DRIVER
SERVICE_TYPE_ALL
SERVICE_STATES
SERVICE_TYPES
AF_OP_ACCOUNTS
AF_OP_COMM
AF_OP_PRINT
AF_OP_SERVER
ALLOCATE_RESPONSE
AuditCategoryAccountLogon
AuditCategoryAccountManagement
AuditCategoryDetailedTracking
AuditCategoryDirectoryServiceAccess
AuditCategoryLogon
AuditCategoryObjectAccess
AuditCategoryPolicyChange
AuditCategoryPrivilegeUse
AuditCategorySystem
AUTH_REQ_ALLOW_ENC_TKT_IN_SKEY
AUTH_REQ_ALLOW_FORWARDABLE
AUTH_REQ_ALLOW_NOADDRESS
AUTH_REQ_ALLOW_POSTDATE
AUTH_REQ_ALLOW_PROXIABLE
AUTH_REQ_ALLOW_RENEWABLE
AUTH_REQ_ALLOW_VALIDATE
AUTH_REQ_OK_AS_DELEGATE
AUTH_REQ_PREAUTH_REQUIRED
AUTH_REQ_VALIDATE_CLIENT
Batch
CONNECT_CURRENT_MEDIA
CONNECT_DEFERRED
CONNECT_INTERACTIVE
CONNECT_LOCALDRIVE
CONNECT_NEED_DRIVE
CONNECT_PROMPT
CONNECT_REDIRECT
CONNECT_REFCOUNT
CONNECT_RESERVED
CONNECT_TEMPORARY
CONNECT_UPDATE_PROFILE
CONNECT_UPDATE_RECENT
CONNDLG_CONN_POINT
CONNDLG_HIDE_BOX
CONNDLG_NOT_PERSIST
CONNDLG_PERSIST
CONNDLG_RO_PATH
CONNDLG_USE_MRU
CONNECT_UPDATE_PROFILE
DEF_MAX_PWHIST
DACL_SECURITY_INFORMATION
DISC_NO_FORCE
DISC_UPDATE_PROFILE
DFS_ADD_VOLUME
DFS_RESTORE_VOLUME
DFS_STORAGE_STATE_ACTIVE
DFS_STORAGE_STATE_OFFLINE
DFS_STORAGE_STATE_ONLINE
DFS_VOLUME_STATE_INCONSISTENT
DFS_VOLUME_STATE_OK
DFS_VOLUME_STATE_OFFLINE
DFS_VOLUME_STATE_ONLINE
EVENTLOG_BACKWARDS_READ
EVENTLOG_FORWARDS_READ
EVENTLOG_SEEK_READ
EVENTLOG_SEQUENTIAL_READ
EVENTLOG_ERROR_TYPE
EVENTLOG_WARNING_TYPE
EVENTLOG_INFORMATION_TYPE
EVENTLOG_AUDIT_SUCCESS
EVENTLOG_AUDIT_FAILURE
FILTER_INTERDOMAIN_TRUST_ACCOUNT
FILTER_NORMAL_ACCOUNT
FILTER_SERVER_TRUST_ACCOUNT
FILTER_TEMP_DUPLICATE_ACCOUNT
FILTER_WORKSTATION_TRUST_ACCOUNT
GROUP_SECURITY_INFORMATION
IDASYNC
IDTIMEOUT
Interactive
JOB_ADD_CURRENT_DATE
JOB_EXEC_ERROR
JOB_INPUT_FLAGS
JOB_NONINTERACTIVE
JOB_OUTPUT_FLAGS
JOB_RUN_PERIODICALLY
JOB_RUNS_TODAY
KERB_CHECKSUM_CRC32
KERB_CHECKSUM_DES_MAC
KERB_CHECKSUM_DES_MAC_MD5
KERB_CHECKSUM_HMAC_MD5
KERB_CHECKSUM_KRB_DES_MAC
KERB_CHECKSUM_LM
KERB_CHECKSUM_MD25
KERB_CHECKSUM_MD4
KERB_CHECKSUM_MD5
KERB_CHECKSUM_MD5_DES
KERB_CHECKSUM_MD5_HMAC
KERB_CHECKSUM_NONE
KERB_CHECKSUM_RC4_MD5
KERB_CHECKSUM_REAL_CRC32
KERB_CHECKSUM_SHA1
KERB_DECRYPT_FLAG_DEFAULT_KEY
KERB_ETYPE_DES_CBC_CRC
KERB_ETYPE_DES_CBC_MD4
KERB_ETYPE_DES_CBC_MD5
KERB_ETYPE_DES_CBC_MD5_NT
KERB_ETYPE_DES_PLAIN
KERB_ETYPE_DSA_SIGN
KERB_ETYPE_NULL
KERB_ETYPE_PKCS7_PUB
KERB_ETYPE_RC4_HMAC_NT
KERB_ETYPE_RC4_HMAC_NT_EXP
KERB_ETYPE_RC4_HMAC_OLD
KERB_ETYPE_RC4_HMAC_OLD_EXP
KERB_ETYPE_RC4_LM
KERB_ETYPE_RC4_MD4
KERB_ETYPE_RC4_PLAIN
KERB_ETYPE_RC4_PLAIN_EXP
KERB_ETYPE_RC4_PLAIN_OLD
KERB_ETYPE_RC4_PLAIN_OLD_EXP
KERB_ETYPE_RC4_PLAIN2
KERB_ETYPE_RC4_SHA
KERB_ETYPE_RSA_PRIV
KERB_ETYPE_RSA_PUB
KERB_ETYPE_RSA_PUB_MD5
KERB_ETYPE_RSA_PUB_SHA1
KERB_RETRIEVE_TICKET_DONT_USE_CACHE
KERB_RETRIEVE_TICKET_USE_CACHE_ONLY
KERB_WRAP_NO_ENCRYPT
KERBEROS_REVISION
KERBEROS_VERSION
KerbInteractiveLogon
KerbSmartCardLogon
KerbInteractiveProfile
KerbSmartCardProfile
LG_INCLUDE_INDIRECT
LOGON_CACHED_ACCOUNT
LOGON_EXTRA_SIDS
LOGON_GRACE_LOGON
LOGON_GUEST
LOGON_NOENCRYPTION
LOGON_PROFILE_PATH_RETURNED
LOGON_RESOURCE_GROUPS
LOGON_SERVER_TRUST_ACCOUNT
LOGON_SUBAUTH_SESSION_KEY
LOGON_USED_LM_PASSWORD
LSA_MODE_INDIVIDUAL_ACCOUNTS
LSA_MODE_LOG_FULL
LSA_MODE_MANDATORY_ACCESS
LSA_MODE_PASSWORD_PROTECTED
MAJOR_VERSION_MASK
MsV1_0InteractiveLogon
MsV1_0Lm20Logon
MsV1_0NetworkLogon
MsV1_0SubAuthLogon
MsV1_0InteractiveProfile
MsV1_0Lm20LogonProfile
MsV1_0SmartCardProfile
MsV1_0EnumerateUsers
MsV1_0CacheLogon
MsV1_0CacheLookup
MsV1_0ChangeCachedPassword
MsV1_0ChangePassword
MsV1_0DeriveCredential
MsV1_0GenericPassthrough
MsV1_0GetUserInfo
MsV1_0Lm20ChallengeRequest
MsV1_0Lm20GetChallengeResponse
MsV1_0ReLogonUsers
MsV1_0SubAuth
MSV1_0_CHALLENGE_LENGTH
MSV1_0_USER_SESSION_KEY_LENGTH
MSV1_0_LANMAN_SESSION_KEY_LENGTH
MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
MSV1_0_CLEARTEXT_PASSWORD_ALLOWED
MSV1_0_DERIVECRED_TYPE_SHA1
MSV1_0_DONT_TRY_GUEST_ACCOUNT
MSV1_0_RETURN_PASSWORD_EXPIRY
MSV1_0_RETURN_PROFILE_PATH
MSV1_0_RETURN_USER_PARAMETERS
MSV1_0_SUBAUTHENTICATION_DLL_EX
MSV1_0_TRY_GUEST_ACCOUNT_ONLY
MSV1_0_TRY_SPECIFIED_DOMAIN_ONLY
MSV1_0_UPDATE_LOGON_STATISTICS
MSV1_0_MNS_LOGON
MSV1_0_SUBAUTHENTICATION_DLL
MSV1_0_SUBAUTHENTICATION_DLL_SHIFT
MSV1_0_SUBAUTHENTICATION_DLL_IIS
MSV1_0_SUBAUTHENTICATION_DLL_RAS
MSV1_0_SUBAUTHENTICATION_FLAGS
MSV1_0_CRED_LM_PRESENT
MSV1_0_CRED_NT_PRESENT
MSV1_0_CRED_VERSION
MSV1_0_OWF_PASSWORD_LENGTH
MSV1_0_NTLM3_OWF_LENGTH
MSV1_0_NTLM3_RESPONSE_LENGTH
MSV1_0_MAX_AVL_SIZE
MSV1_0_MAX_NTLM3_LIFE
MSV1_0_NTLM3_INPUT_LENGTH
MsvAvEOL
MsvAvNbComputerName
MsvAvNbDomainName
MsvAvDnsDomainName
MsvAvDnsServerName
NegCallPackageMax
NegEnumPackagePrefixes
NEGOTIATE_MAX_PREFIX
NETLOGON_CONTROL_BACKUP_CHANGE_LOG
NETLOGON_CONTROL_BREAKPOINT
NETLOGON_CONTROL_FIND_USER
NETLOGON_CONTROL_PDC_REPLICATE
NETLOGON_CONTROL_QUERY
NETLOGON_CONTROL_REDISCOVER
NETLOGON_CONTROL_REPLICATE
NETLOGON_CONTROL_SET_DBFLAG
NETLOGON_CONTROL_SYNCHRONIZE
NETLOGON_CONTROL_TC_QUERY
NETLOGON_CONTROL_TRANSPORT_NOTIFY
NETLOGON_CONTROL_TRUNCATE_LOG
NETLOGON_CONTROL_UNLOAD_NETLOGON_DLL
NETLOGON_FULL_SYNC_REPLICATION
NETLOGON_REDO_NEEDED
NETLOGON_REPLICATION_IN_PROGRESS
NETLOGON_REPLICATION_NEEDED
NetSetupDnsMachine
NetSetupDomain
NetSetupDomainName
NetSetupMachine
NetSetupNonExistentDomain
NetSetupUnjoined
NetSetupUnknown
NetSetupUnknownStatus
NetSetupWorkgroup
NetSetupWorkgroupName
NETSETUP_ACCT_CREATE
NETSETUP_ACCT_DELETE
NETSETUP_DOMAIN_JOIN_IF_JOINED
NETSETUP_INSTALL_INVOCATION
NETSETUP_JOIN_DOMAIN
NETSETUP_JOIN_UNSECURE
NETSETUP_WIN9X_UPGRADE
NETPROPERTY_PERSISTENT
Network
NO_PERMISSION_REQUIRED
ONE_DAY
OWNER_SECURITY_INFORMATION
PERM_FILE_CREATE
PERM_FILE_READ
PERM_FILE_WRITE
POLICY_AUDIT_EVENT_FAILURE
POLICY_AUDIT_EVENT_NONE
POLICY_AUDIT_EVENT_MASK
POLICY_AUDIT_EVENT_NONE
POLICY_AUDIT_EVENT_SUCCESS
POLICY_AUDIT_EVENT_UNCHANGED
POLICY_ALL_ACCESS
POLICY_AUDIT_LOG_ADMIN
POLICY_CREATE_ACCOUNT
POLICY_CREATE_PRIVILEGE
POLICY_CREATE_SECRET
POLICY_EXECUTE
POLICY_GET_PRIVATE_INFORMATION
POLICY_LOOKUP_NAMES
POLICY_NOTIFICATION
POLICY_READ
POLICY_SERVER_ADMIN
POLICY_SET_AUDIT_REQUIREMENTS
POLICY_SET_DEFAULT_QUOTA_LIMITS
POLICY_TRUST_ADMIN
POLICY_VIEW_AUDIT_INFORMATION
POLICY_VIEW_LOCAL_INFORMATION
POLICY_WRITE
POLICY_QOS_ALLOW_LOCAL_ROOT_CERT_STORE
POLICY_QOS_DHCP_SERVER_ALLOWED
POLICY_QOS_INBOUND_CONFIDENTIALITY
POLICY_QOS_INBOUND_INTEGRITY
POLICY_QOS_OUTBOUND_CONFIDENTIALITY
POLICY_QOS_OUTBOUND_INTEGRITY
POLICY_QOS_RAS_SERVER_ALLOWED
POLICY_QOS_SCHANNEL_REQUIRED
PolicyAccountDomainInformation
PolicyAuditEventsInformation
PolicyAuditFullQueryInformation
PolicyAuditFullSetInformation
PolicyAuditLogInformation
PolicyDefaultQuotaInformation
PolicyDnsDomainInformation
PolicyLsaServerRoleInformation
PolicyModificationInformation
PolicyPdAccountInformation
PolicyPrimaryDomainInformation
PolicyReplicaSourceInformation
PolicyDomainEfsInformation
PolicyDomainKerberosTicketInformation
PolicyDomainQualityOfServiceInformation
PolicyNotifyAccountDomainInformation
PolicyNotifyAuditEventsInformation
PolicyNotifyDnsDomainInformation
PolicyNotifyDomainEfsInformation
PolicyNotifyDomainKerberosTicketInformation
PolicyNotifyMachineAccountPasswordInformation
PolicyNotifyServerRoleInformation
PolicyServerDisabled
PolicyServerEnabled
PolicyServerRoleBackup
PolicyServerRolePrimary
Proxy
REMOTE_NAME_INFO_LEVEL
REPL_EXTENT_FILE
REPL_EXTENT_TREE
REPL_INTEGRITY_TREE
REPL_INTEGRITY_FILE
REPL_ROLE_BOTH
REPL_ROLE_EXPORT
REPL_ROLE_IMPORT
REPL_STATE_OK
REPL_STATE_NO_MASTER
REPL_STATE_NO_SYNC
REPL_STATE_NEVER_REPLICATED
REPL_UNLOCK_FORCE
REPL_UNLOCK_NOFORCE
RESOURCEUSAGE_ALL
RESOURCE_CONNECTED
RESOURCE_CONTEXT
RESOURCE_GLOBALNET
RESOURCE_REMEMBERED
RESOURCETYPE_RESERVED
RESOURCETYPE_UNKNOWN
RESOURCETYPE_ANY
RESOURCETYPE_DISK
RESOURCETYPE_PRINT
RESOURCEDISPLAYTYPE_DIRECTORY
RESOURCEDISPLAYTYPE_DOMAIN
RESOURCEDISPLAYTYPE_FILE
RESOURCEDISPLAYTYPE_GENERIC
RESOURCEDISPLAYTYPE_GROUP
RESOURCEDISPLAYTYPE_NDSCONTAINER
RESOURCEDISPLAYTYPE_NETWORK
RESOURCEDISPLAYTYPE_ROOT
RESOURCEDISPLAYTYPE_SERVER
RESOURCEDISPLAYTYPE_SHARE
RESOURCEDISPLAYTYPE_SHAREADMIN
RESOURCEDISPLAYTYPE_TREE
RESOURCEUSAGE_ALL
RESOURCEUSAGE_CONNECTABLE
RESOURCEUSAGE_CONTAINER
RESOURCEUSAGE_ATTACHED
RESOURCEUSAGE_NOLOCALDEVICE
RESOURCEUSAGE_RESERVED
RESOURCEUSAGE_SIBLING
SACL_SECURITY_INFORMATION
SE_GROUP_ENABLED_BY_DEFAULT
SE_GROUP_MANDATORY
SE_GROUP_OWNER
SE_CREATE_TOKEN_NAME
SE_ASSIGNPRIMARYTOKEN_NAME
SE_LOCK_MEMORY_NAME
SE_INCREASE_QUOTA_NAME
SE_UNSOLICITED_INPUT_NAME
SE_MACHINE_ACCOUNT_NAME
SE_TCB_NAME
SE_SECURITY_NAME
SE_TAKE_OWNERSHIP_NAME
SE_LOAD_DRIVER_NAME
SE_SYSTEM_PROFILE_NAME
SE_SYSTEMTIME_NAME
SE_PROF_SINGLE_PROCESS_NAME
SE_INC_BASE_PRIORITY_NAME
SE_CREATE_PAGEFILE_NAME
SE_CREATE_PERMANENT_NAME
SE_BACKUP_NAME
SE_RESTORE_NAME
SE_SHUTDOWN_NAME
SE_DEBUG_NAME
SE_AUDIT_NAME
SE_SYSTEM_ENVIRONMENT_NAME
SE_CHANGE_NOTIFY_NAME
SE_REMOTE_SHUTDOWN_NAME
SE_INTERACTIVE_LOGON_NAME
SE_DENY_INTERACTIVE_LOGON_NAME
SE_NETWORK_LOGON_NAME
SE_DENY_NETWORK_LOGON_NAME
SE_BATCH_LOGON_NAME
SE_DENY_BATCH_LOGON_NAME
SE_SERVICE_LOGON_NAME
SE_DENY_SERVICE_LOGON_NAME
Service
SC_ACTION_NONE
SC_ACTION_REBOOT
SC_ACTION_RESTART
SC_ACTION_RUN_COMMAND
SC_MANAGER_ALL_ACCESS
SC_MANAGER_CONNECT
SC_MANAGER_CREATE_SERVICE
SC_MANAGER_ENUMERATE_SERVICE
SC_MANAGER_LOCK
SC_MANAGER_MODIFY_BOOT_CONFIG
SC_MANAGER_QUERY_LOCK_STATUS
SC_STATUS_PROCESS_INFO
SERVICE_ACCEPT_STOP
SERVICE_ACCEPT_PAUSE_CONTINUE
SERVICE_ACCEPT_SHUTDOWN
SERVICE_ACCEPT_PARAMCHANGE
SERVICE_ACCEPT_NETBINDCHANGE
SERVICE_ACCEPT_HARDWAREPROFILECHANGE
SERVICE_ACCEPT_POWEREVENT
SERVICE_FILE_SYSTEM_DRIVER
SERVICE_INTERACTIVE_PROCESS
SERVICE_KERNEL_DRIVER
SERVICE_WIN32_OWN_PROCESS
SERVICE_WIN32_SHARE_PROCESS
SERVICE_AUTO_START
SERVICE_BOOT_START
SERVICE_DEMAND_START
SERVICE_DISABLED
SERVICE_SYSTEM_START
SERVICE_ERROR_CRITICAL
SERVICE_ERROR_IGNORE
SERVICE_ERROR_NORMAL
SERVICE_ERROR_SEVERE
SERVICE_CONTINUE_PENDING
SERVICE_PAUSE_PENDING
SERVICE_PAUSED
SERVICE_RUNNING
SERVICE_START_PENDING
SERVICE_STOPPED
SERVICE_STOP_PENDING
SERVICE_ALL_ACCESS
SERVICE_CHANGE_CONFIG
SERVICE_ENUMERATE_DEPENDENTS
SERVICE_INTERROGATE
SERVICE_PAUSE_CONTINUE
SERVICE_QUERY_CONFIG
SERVICE_QUERY_STATUS
SERVICE_START
SERVICE_STOP
SERVICE_USER_DEFINED_CONTROL
SERVICE_RUNS_IN_SYSTEM_PROCESS
SERVICE_CONTROL_CONTINUE
SERVICE_CONTROL_DEVICEEVENT
SERVICE_CONTROL_HARDWAREPROFILECHANGE
SERVICE_CONTROL_INTERROGATE
SERVICE_CONTROL_NETBINDADD
SERVICE_CONTROL_NETBINDDISABLE
SERVICE_CONTROL_NETBINDENABLE
SERVICE_CONTROL_NETBINDREMOVE
SERVICE_CONTROL_PAUSE
SERVICE_CONTROL_PARAMCHANGE
SERVICE_CONTROL_POWEREVENT
SERVICE_CONTROL_SHUTDOWN
SERVICE_CONTROL_STOP
SERVICE_CONFIG_FAILURE_ACTIONS
SERVICE_NO_CHANGE
SERVICE_ACTIVE
SERVICE_DRIVER
SERVICE_INACTIVE
SERVICE_STATE_ALL
SERVICE_WIN32
STYPE_DEVICE
STYPE_DISKTREE
STYPE_IPC
STYPE_PRINTQ
SUPPORTS_ANY
SUPPORTS_LOCAL
SUPPORTS_REMOTE_ADMIN_PROTOCOL
SUPPORTS_RPC
SUPPORTS_SAM_PROTOCOL
SUPPORTS_UNICODE
SV_HIDDEN
SV_MAX_CMD_LEN
SV_MAX_SRV_HEUR_LEN
SV_NODISC
SV_PLATFORM_ID_OS2
SV_PLATFORM_ID_NT
SV_SHARESECURITY
SV_TYPE_AFP
SV_TYPE_ALL
SV_TYPE_ALTERNATE_XPORT
SV_TYPE_BACKUP_BROWSER
SV_TYPE_CLUSTER_NT
SV_TYPE_DCE
SV_TYPE_DFS
SV_TYPE_DIALIN_SERVER
SV_TYPE_DOMAIN_BAKCTRL
SV_TYPE_DOMAIN_CTRL
SV_TYPE_DOMAIN_ENUM
SV_TYPE_DOMAIN_MASTER
SV_TYPE_DOMAIN_MEMBER
SV_TYPE_LOCAL_LIST_ONLY
SV_TYPE_MASTER_BROWSER
SV_TYPE_NOVELL
SV_TYPE_NT
SV_TYPE_POTENTIAL_BROWSER
SV_TYPE_PRINTQ_SERVER
SV_TYPE_SERVER
SV_TYPE_SERVER_MFPN
SV_TYPE_SERVER_NT
SV_TYPE_SERVER_OSF
SV_TYPE_SERVER_UNIX
SV_TYPE_SERVER_VMS
SV_TYPE_SQLSERVER
SV_TYPE_TERMINALSERVER
SV_TYPE_TIME_SOURCE
SV_TYPE_WFW
SV_TYPE_WINDOWS
SV_TYPE_WORKSTATION
SV_TYPE_XENIX_SERVER
SV_USERS_PER_LICENSE
SV_USERSECURITY
SV_VISIBLE
SW_AUTOPROF_LOAD_MASK
SW_AUTOPROF_SAVE_MASK
TIMEQ_FOREVER
TRUST_ATTRIBUTE_NON_TRANSITIVE
TRUST_ATTRIBUTE_TREE_PARENT
TRUST_ATTRIBUTE_TREE_ROOT
TRUST_ATTRIBUTE_UPLEVEL_ONLY
TRUST_ATTRIBUTES_USER
TRUST_ATTRIBUTES_VALID
TRUST_AUTH_TYPE_CLEAR
TRUST_AUTH_TYPE_NONE
TRUST_AUTH_TYPE_NT4OWF
TRUST_AUTH_TYPE_VERSION
TRUST_DIRECTION_BIDIRECTIONAL
TRUST_DIRECTION_DISABLED
TRUST_DIRECTION_INBOUND
TRUST_DIRECTION_OUTBOUND
TRUST_TYPE_DCE
TRUST_TYPE_DOWNLEVEL
TRUST_TYPE_MIT
TRUST_TYPE_UPLEVEL
TrustedControllersInformation
TrustedDomainAuthInformation
TrustedDomainFullInformation
TrustedDomainInformationBasic
TrustedDomainInformationEx
TrustedDomainNameInformation
TrustedPasswordInformation
TrustedPosixOffsetInformation
UAS_ROLE_STANDALONE
UAS_ROLE_MEMBER
UAS_ROLE_BACKUP
UAS_ROLE_PRIMARY
UF_ACCOUNT_TYPE_MASK
UF_ACCOUNTDISABLE
UF_DONT_EXPIRE_PASSWD
UF_DONT_REQUIRE_PREAUTH
UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED
UF_HOMEDIR_REQUIRED
UF_INTERDOMAIN_TRUST_ACCOUNT
UF_LOCKOUT
UF_MACHINE_ACCOUNT_MASK
UF_MNS_LOGON_ACCOUNT
UF_NORMAL_ACCOUNT
UF_NOT_DELEGATED
UF_PASSWD_CANT_CHANGE
UF_PASSWD_NOTREQD
UF_SCRIPT
UF_SERVER_TRUST_ACCOUNT
UF_SETTABLE_BITS
UF_SMARTCARD_REQUIRED
UF_TEMP_DUPLICATE_ACCOUNT
UF_TRUSTED_FOR_DELEGATION
UF_USE_DES_KEY_ONLY
UF_WORKSTATION_TRUST_ACCOUNT
UNITS_PER_WEEK
UNIVERSAL_NAME_INFO_LEVEL
Unlock
USE_FORCE
USE_LOTS_OF_FORCE
USE_NOFORCE
USE_SPECIFIC_TRANSPORT
USE_CHARDEV
USE_CONN
USE_DISCONN
USE_DISKDEV
USE_IPC
USE_NETERR
USE_OK
USE_PAUSED
USE_RECONN
USE_SESSLOST
USE_SPOOLDEV
USE_WILDCARD
USER_MAXSTORAGE_UNLIMITED
USER_PRIV_ADMIN
USER_PRIV_GUEST
USER_PRIV_USER
WNCON_DYNAMIC
WNCON_FORNETCARD
WNCON_NOTROUTED
WNCON_SLOWLINK
WNNC_CRED_MANAGER
WNNC_NET_10NET
WNNC_NET_3IN1
WNNC_NET_9TILES
WNNC_NET_APPLETALK
WNNC_NET_AS400
WNNC_NET_AVID
WNNC_NET_BMC
WNNC_NET_BWNFS
WNNC_NET_CLEARCASE
WNNC_NET_COGENT
WNNC_NET_CSC
WNNC_NET_DCE
WNNC_NET_DECORB
WNNC_NET_DISTINCT
WNNC_NET_DOCUSPACE
WNNC_NET_EXTENDNET
WNNC_NET_FARALLON
WNNC_NET_FJ_REDIR
WNNC_NET_FTP_NFS
WNNC_NET_FRONTIER
WNNC_NET_HOB_NFS
WNNC_NET_IBMAL
WNNC_NET_INTERGRAPH
WNNC_NET_LANMAN
WNNC_NET_LANTASTIC
WNNC_NET_LANSTEP
WNNC_NET_LIFENET
WNNC_NET_LOCUS
WNNC_NET_MANGOSOFT
WNNC_NET_MASFAX
WNNC_NET_MSNET
WNNC_NET_NETWARE
WNNC_NET_OBJECT_DIRE
WNNC_NET_PATHWORKS
WNNC_NET_POWERLAN
WNNC_NET_PROTSTOR
WNNC_NET_RDR2SAMPLE
WNNC_NET_SERNET
WNNC_NET_SHIVA
WNNC_NET_SUN_PC_NFS
WNNC_NET_SYMFONET
WNNC_NET_TWINS
WNNC_NET_VINES
WTS_CURRENT_SERVER
WTS_CURRENT_SERVER_HANDLE
WTS_CURRENT_SERVER_NAME
WTS_CURRENT_SESSION
WTS_EVENT_NONE
WTS_EVENT_CREATE
WTS_EVENT_DELETE
WTS_EVENT_RENAME
WTS_EVENT_CONNECT
WTS_EVENT_DISCONNECT
WTS_EVENT_LOGON
WTS_EVENT_LOGOFF
WTS_EVENT_STATECHANGE
WTS_EVENT_LICENSE
WTS_EVENT_ALL
WTS_EVENT_FLUSH
WTS_WSD_FASTREBOOT
WTS_WSD_LOGOFF
WTS_WSD_POWEROFF
WTS_WSD_REBOOT
WTS_WSD_SHUTDOWN
WTSActive
WTSConnected
WTSConnectQuery
WTSShadow
WTSDisconnected
WTSIdle
WTSListen
WTSReset
WTSDown
WTSInit
WTSApplicationName
WTSClientAddress
WTSClientBuildNumber
WTSClientDirectory
WTSClientDisplay
WTSClientHardwareId
WTSClientName
WTSClientProductId
WTSConnectState
WTSDomainName
WTSInitialProgram
WTSOEMId
WTSSessionId
WTSUserName
WTSWinStationName
WTSWorkingDirectory
WTSUserConfigInitialProgram
WTSUserConfigWorkingDirectory
WTSUserConfigfInheritInitialProgram
WTSUserConfigfAllowLogonTerminalServer
WTSUserConfigTimeoutSettingsConnections
WTSUserConfigTimeoutSettingsDisconnections
WTSUserConfigTimeoutSettingsIdle
WTSUserConfigfDeviceClientDrives
WTSUserConfigfDeviceClientPrinters
WTSUserConfigfDeviceClientDefaultPrinter
WTSUserConfigBrokenTimeoutSettings
WTSUserConfigReconnectSettings
WTSUserConfigModemCallbackSettings
WTSUserConfigModemCallbackPhoneNumber
WTSUserConfigShadowingSettings
WTSUserConfigTerminalServerProfilePath
WTSUserConfigTerminalServerHomeDir
WTSUserConfigTerminalServerHomeDirDrive
WTSUserConfigfTerminalServerRemoteHomeDir
The following hashes are useful, since they group several associated codes form the platform sdk together, or provide description for the constants. For each hash we describe its use and mention some functions it may be used with. This is work in progress and should be finished by the next release.
I_NetLogonControl ---
I_NetLogonControl2 ---
LogonControlQuery ---
LogonControlReplicate ---
LogonControlSynchronize ---
LogonControlPdcReplicate ---
LogonControlRediscover ---
LogonControlTCQuery ---
LogonControlTransportNotify ---
LogonControlFindUser ---
NetEnumerateTrustedDomains ---
I_NetGetDCList
LsaQueryInformationPolicy ---
LsaSetInformationPolicy ---
LsaQueryAuditLogPolicy ---
LsaQueryAuditEventsPolicy ---
LsaSetAuditEventsPolicy ---
LsaQueryPrimaryDomainPolicy ---
LsaSetPrimaryDomainPolicy ---
LsaQueryPdAccountPolicy ---
LsaQueryAccountDomainPolicy ---
LsaSetAccountDomainPolicy ---
LsaQueryServerRolePolicy ---
LsaSetServerRolePolicy ---
LsaQueryReplicaSourcePolicy ---
LsaSetReplicaSourcePolicy ---
LsaQueryDefaultQuotaPolicy ---
LsaSetDefaultQuotaPolicy ---
LsaQueryAuditFullPolicy ---
LsaSetAuditFullPolicy ---
LsaQueryDnsDomainPolicy ---
LsaSetDnsDomainPolicy ---
LsaQueryTrustedDomainInfo ---
LsaSetTrustedDomainInformation ---
LsaSetTrustedDomainInfo ---
LsaQueryTrustedDomainNameInfo ---
LsaSetTrustedDomainNameInfo ---
LsaQueryTrustedPosixOffsetInfo ---
LsaSetTrustedPosixOffsetInfo ---
LsaQueryTrustedPasswordInfo ---
LsaSetTrustedPasswordInfo ---
LsaRetrievePrivateData ---
LsaStorePrivateData ---
LsaEnumerateTrustedDomains ---
LsaLookupNames ---
LsaLookupSids ---
LsaEnumerateAccountsWithUserRight ---
LsaEnumerateAccountRights ---
LsaAddAccountRights ---
LsaRemoveAccountRights
GrantPrivilegeToAccount ---
RevokePrivilegeFromAccount ---
EnumAccountPrivileges ---
EnumPrivilegeAccounts
NetDfsAdd ---
NetDfsEnum ---
NetDfsGetInfo ---
NetDfsRemove ---
NetDfsSetInfo ---
NetDfsMove ---
NetDfsRename ---
NetDfsAddFtRoot ---
NetDfsRemoveFtRoot ---
NetDfsRemoveFtRootForced ---
NetDfsAddStdRoot ---
NetDfsAddStdRootForced ---
NetDfsRemoveStdRoot ---
NetDfsManagerInitialize ---
NetDfsGetClientInfo ---
NetDfsSetClientInfo ---
NetDfsGetDcAddress
NetGetJoinableOUs ---
NetGetJoinInformation ---
NetJoinDomain ---
NetRenameMachineInDomain ---
NetUnjoinDomain ---
NetValidateName ---
NetRegisterDomainNameChangeNotification ---
NetUnregisterDomainNameChangeNotification
NetFileClose ---
NetFileEnum ---
NetFileGetInfo
MultinetGetConnectionPerformance ---
NetGetAnyDCName ---
NetGetDCName ---
NetGetDisplayInformationIndex ---
NetQueryDisplayInformation
NetGroupAdd ---
NetGroupAddUser ---
NetGroupDel ---
NetGroupDelUser ---
NetGroupEnum ---
NetGroupGetInfo ---
NetGroupGetUsers ---
NetGroupSetInfo ---
NetGroupSetUsers
NetLocalGroupAdd ---
NetLocalGroupAddMember ---
NetLocalGroupAddMembers ---
NetLocalGroupAddMembersBySid ---
NetLocalGroupDel ---
NetLocalGroupDelMember ---
NetLocalGroupDelMembers ---
NetLocalGroupDelMembersBySid ---
NetLocalGroupEnum ---
NetLocalGroupGetInfo ---
NetLocalGroupGetMembers ---
NetLocalGroupSetInfo ---
NetLocalGroupSetMembers ---
NetLocalGroupSetMembersBySid
NetMessageBufferSend ---
NetMessageNameAdd ---
NetMessageNameDel ---
NetMessageNameEnum ---
NetMessageNameGetInfo
NetRemoteTOD ---
NetRemoteComputerSupports
NetReplExportDirAdd ---
NetReplExportDirDel ---
NetReplExportDirEnum ---
NetReplExportDirGetInfo ---
NetReplExportDirLock ---
NetReplExportDirSetInfo ---
NetReplExportDirUnlock ---
NetReplGetInfo ---
NetReplImportDirAdd ---
NetReplImportDirDel ---
NetReplImportDirEnum ---
NetReplImportDirGetInfo ---
NetReplImportDirLock ---
NetReplImportDirUnlock ---
NetReplSetInfo
NetScheduleJobAdd ---
NetScheduleJobDel ---
NetScheduleJobEnum ---
NetScheduleJobGetInfo
NetServerDiskEnum ---
NetServerEnum ---
NetServerGetInfo ---
NetServerSetInfo ---
NetServerTransportAdd ---
NetServerTransportDel ---
NetServerTransportEnum
NetSessionDel ---
NetSessionEnum ---
NetSessionGetInfo
NetShareAdd ---
NetShareCheck ---
NetShareDel ---
NetShareEnum ---
NetShareGetInfo ---
NetShareSetInfo ---
NetConnectionEnum
NetUserAdd ---
NetUserChangePassword ---
NetUserCheckPassword ---
NetUserDel ---
NetUserEnum ---
NetUserGetGroups ---
NetUserGetInfo ---
NetUserGetLocalGroups ---
NetUserSetGroups ---
NetUserSetInfo ---
NetUserSetProp ---
NetUserModalsGet ---
NetUserModalsSet
NetWkstaGetInfo ---
NetWkstaSetInfo ---
NetWkstaTransportAdd ---
NetWkstaTransportDel ---
NetWkstaTransportEnum ---
NetWkstaUserGetInfo ---
NetWkstaUserSetInfo ---
NetWkstaUserEnum
WNetAddConnection ---
WNetCancelConnection ---
WNetEnumResource ---
WNetConnectionDialog ---
WNetDisconnectDialog ---
WNetGetConnection ---
WNetGetNetworkInformation ---
WNetGetProviderName ---
WNetGetResourceInformation ---
WNetGetResourceParent ---
WNetGetUniversalName ---
WNetGetUser ---
WNetUseConnection
StartService ---
StopService ---
PauseService ---
ContinueService ---
InterrogateService ---
ControlService ---
CreateService ---
DeleteService ---
EnumServicesStatus ---
EnumDependentServices ---
ChangeServiceConfig ---
GetServiceDisplayName ---
GetServiceKeyName ---
LockServiceDatabase ---
UnlockServiceDatabase ---
QueryServiceLockStatus ---
QueryServiceConfig ---
QueryServiceStatus ---
QueryServiceObjectSecurity ---
SetServiceObjectSecurity ---
QueryServiceConfig2 ---
ChangeServiceConfig2 ---
QueryServiceStatusEx ---
EnumServicesStatusEx
ReadEventLog ---
GetEventDescription ---
BackupEventLog ---
ClearEventLog ---
ReportEvent ---
GetNumberOfEventLogRecords ---
GetOldestEventLogRecord
WTSEnumerateServers ---
WTSOpenServer ---
WTSCloseServer ---
WTSEnumerateSessions ---
WTSEnumerateProcesses ---
WTSTerminateProcess ---
WTSQuerySessionInformation ---
WTSQueryUserConfig ---
WTSSetUserConfig ---
WTSSendMessage ---
WTSDisconnectSession ---
WTSLogoffSession ---
WTSShutdownSystem ---
WTSWaitSystemEvent
SidToString ---
StringToSid ---
GuidToString ---
StringToGuid
This version of Win32::Lanman now supports/implements specific calls which are only available in Windows 2000. If you call one of these
routines from NT4, the call will fail and GetLastError() returns the code 127 (procedure not found).
All of the functions return false if they fail. You can call Win32::Lanman::GetLastError() to get more error information.
Throughout $server is the name of the server you want the call to run against. If set to '', this signifies the local machine.
In previous versions of this module, you were required to put two backslashes before the server name, as you would do at the cmd prompt, but from version 1.05 all server names will be automatically prefaced by two backslashes if they are missing.
Note: Win32::Lanman defines some private error codes, which are not currently exported. You cannot call ``net helpmsg'' for a description of these. Instead you can find the meaning in the usererror.h file included as part of the distribution.
Here we use the term <C storage> to mean a root share, (Dfs path) associated with a Dfs link. Throughout this section if you specify a server and share the function applies to the server and share within the dfs tree. If you leave them empty, the function runs relative to the dfsroot.
NetDfsManagerInitialize($server)
if(!Win32::Lanman::NetDfsAdd("\\\\testdfsserver\\dfsrootdir\\dfsdir",
"testserver1", "testshare1", "comment", &Win32::Lanman::DFS_ADD_VOLUME))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
add an additional storage space to an existing dfs volume
if(!Win32::Lanman::NetDfsAdd("\\\\testdfsserver\\dfsrootdir\\dfsdir", "testserver2", "testshare2", "comment", &Win32::Lanman::DFS_RESTORE_VOLUME))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsEnum("\\\\testserver", \@dfs))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $dfspath (@dfs)
{
print "${$dfspath}{'entrypath'}\t${$dfspath}{'comment'}\t${$dfspath}{'state'}\n";
if(exists(${$dfspath}{'storage'}))
{
$storage = ${$dfspath}{'storage'};
for($count = 0; $count <= $#$storage; $count++)
{
print "\t${$$storage[$count]}{'servername'}";
print "\t${$$storage[$count]}{'sharename'}";
print "\t${$$storage[$count]}{'state'}\n";
}
}
}
if(!Win32::Lanman::NetDfsGetInfo("\\\\testdfsserver\\dfsrootdir\\dfsdir", "testserver2", "testshare2", \%dfs))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$dfs{'entrypath'}\t$dfs{'comment'}\t$dfs{'state'}\n";
if(exists($dfs{'storage'}))
{
$store = $dfs{'storage'};
for($count = 0; $count <= $#$store; $count++)
{
print "\t${$$store[$count]}{'servername'}";
print "\t${$$store[$count]}{'sharename'}";
print "\t${$$store[$count]}{'state'}\n";
}
}
gets information about volume \\testdfsserver\dfsrootdir\dfsdir and all storages in \\testdfsserver\dfsrootdir\dfsdir
if(!Win32::Lanman::NetDfsGetInfo("\\\\testdfsserver\\dfsrootdir\\dfsdir", '', '', \%dfs))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$dfs{'entrypath'}\t$dfs{'comment'}\t$dfs{'state'}\n";
if(exists($dfs{'storage'}))
{
$store = $dfs{'storage'};
for($count = 0; $count <= $#$store; $count++)
{
print "\t${$$store[$count]}{'server'}";
print "\t${$$store[$count]}{'share'}";
print "\t${$$store[$count]}{'state'}\n";
}
}
if(!Win32::Lanman::NetDfsRemove("\\\\testdfsserver\\dfsrootdir\\dfsdir", "testserver2", "testshare2"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsSetInfo("\\\\testdfsserver\\dfsrootdir\\dfsdir", '', '', {'comment' => 'this is a volume name'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsSetInfo("\\\\testserver", "testdfs", "testroot", "test comment"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsRemoveFtRoot("\\\\testserver", "testdfs", "testroot"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsRemoveFtRootForced("testdomain.com", "\\\\testserver", "testdfs",
"testroot"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsAddStdRoot("\\\\testserver", "testroot", "test comment"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsAddStdRootForced("\\\\testserver", "testroot", "c:\\testdir",
"test comment"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsRemoveStdRoot("\\\\testserver", "testdfs"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
NetDfsManagerInitialize($server)
if(!Win32::Lanman::NetDfsManagerInitialize("\\\\testserver"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsGetClientInfo("\\\\testserver\\testroot", "", "", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys info)
{
if($key eq "storage")
{
foreach $count (0 .. $#{$info{$key}})
{
print "storage[$count]:\n";
foreach $skey (sort keys %{${$info{$key}}[$count]})
{
print "\t$skey=${${$info{$key}}[$count]}{$skey}\n";
}
}
}
else
{
print "$key=$info{$key}\n";
}
}
Retrieves information about the testdfs link in the \\testserver\testroot dfs root.
if(!Win32::Lanman::NetDfsGetClientInfo("\\\\testserver\\testroot", "\\\\testserver", "testdfs",
\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsSetClientInfo("\\\\testserver\\testroot", "\\\\testserver", "testdfs",
{ tomeout => 200 }))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetDfsGetDcAddress("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys info)
{
print "$key=$info{$key}\n";
}
The following functions are related to The Active Directory.
NetRegisterDomainNameChangeNotification($notification_handle)NetUnregisterDomainNameChangeNotification($notification_handle)
if(!Win32::Lanman::NetGetJoinableOUs("\\\\testserver", "testdomain.com", "testaccount", "testpassword", \@ous))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $ou(@ous)
{
print "$ou\n";
}
if(!Win32::Lanman::NetGetJoinInformation("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetJoinDomain("\\\\testserver", "testdomain.com", "testou", "testaccount",
"testpassword", &NETSETUP_JOIN_DOMAIN | &NETSETUP_DOMAIN_JOIN_IF_JOINED))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetRenameMachineInDomain("\\\\testserver", "testcomputer", "testaccount",
"testpassword", &NETSETUP_ACCT_CREATE))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUnjoinDomain("\\\\testserver", "testaccount", "testpassword"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetValidateName("\\\\testserver", "testdomain", "testaccount", "testpassword",
&NetSetupDomain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
NetRegisterDomainNameChangeNotification($notification_handle)# you must have a valid handle # $handle =
if(!Win32::Lanman::NetRegisterDomainNameChangeNotification($handle))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
# wait til the handle is signaled # WaitForSingleObject($handle)
NetUnregisterDomainNameChangeNotification($notification_handle)# you must have a valid handle # $handle =
if(!Win32::Lanman::NetUnregisterDomainNameChangeNotification($handle))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
The following sample enumerates all information about all open files on server \\testserver.
if(!Win32::Lanman::NetFileEnum("\\\\testserver", '', '', \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $info (@infos)
{
@keys = keys(%$info);
foreach $key(@keys)
{
print "$key: ${$info}{$key}\n";
}
print "\n";
}
The following code supplies information about all open files below c:\winnt opened by user testuser on server \\testserver.
if(!Win32::Lanman::NetFileEnum("\\\\testserver", "c:\\winnt", "testuser", \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $info (@infos)
{
@keys = keys(%$info);
foreach $key(@keys)
{
print "$key: ${$info}{$key}\n";
}
print "\n";
}
$fileid = 125;
if(!Win32::Lanman::NetFileGetInfo("\\\\testserver", $fileid, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys(%info);
foreach $key(@keys)
{
print "$key: $info{$key}\n";
}
$fileid = 125;
if(!Win32::Lanman::NetFileClose("\\\\testserver", $fileid))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
In this case proceed as follows: get your pdc or a bdc and execute the NetGetAnyDCName call there.
# your primary domain name $my_domain = "my_domain"; # a trusted domain name $trust_domain = "trust_domain";
# get the pdc on your local machine for $my_domain
NetGetDCName('', $my_domain, \$pdc);
# now get a dc in the trusted domain
NetGetAnyDCName($pdc, $trusted_domain, \$dc);
if(!Win32::Lanman::MultinetGetConnectionPerformance({'remotename' => "\\\\testserver\\ipc\$"}, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys(%info);
foreach $key(@keys)
{
print "$key: $info{$key}\n";
}
if(!Win32::Lanman::MultinetGetConnectionPerformance({'localname' => "f:"}, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys(%info);
foreach $key(@keys)
{
print "$key: $info{$key}\n";
}
if(!Win32::Lanman::NetGetAnyDCName("\\\\testserver", "testdomain", \$dcname))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $dcname;
if(!Win32::Lanman::NetGetDCName("\\\\testserver", "testdomain", \$pdcname))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $pdcname;
if(!Win32::Lanman::NetGetDisplayInformationIndex("\\\\testserver", 1, "test", \$index))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $index;
$index = 12;
while(Win32::Lanman::NetQueryDisplayInformation("\\\\testserver", 1, $index, 10, \@users))
{
foreach $user (@users)
{
print "${$user}{'name'}\t";
print "${$user}{'comment'}\t";
print "${$user}{'full_name'}\t";
print "${$user}{'flags'}\t";
print "${$user}{'user_id'}\t";
print "${$user}{'next_index'}\n";
}
last
if $#users == -1;
$index = ${$users[$#users]}{'next_index'};
}
Dito for machine accounts. Start at machines names beginning with test. We get 20 accounts on each call.
if(!Win32::Lanman::NetGetDisplayInformationIndex("\\\\testserver", 2, "test", \$index))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
while(Win32::Lanman::NetQueryDisplayInformation("\\\\testserver", 2, $index, 20, \@machines))
{
foreach $machine (@machines)
{
print "${$machine}{'name'}\t";
print "${$machine}{'comment'}\t";
print "${$machine}{'flags'}\t";
print "${$machine}{'user_id'}\t";
print "${$machine}{'next_index'}\n";
}
last
if $#machines == -1;
$index = ${$machines[$#machines]}{'next_index'};
}
Dito for group accounts. Start at begin (index position 0). We get 5 accounts on each call.
$index = 0;
while(Win32::Lanman::NetQueryDisplayInformation("\\\\testserver", 3, $index, 5, \@groups))
{
foreach $group (@groups)
{
print "${$group}{'name'}\t";
print "${$group}{'comment'}\t";
print "${$group}{'group_id'}\t";
print "${$group}{'attributes'}\t";
print "${$group}{'next_index'}\n";
}
last
if $#groups == -1;
$index = ${$groups[$#groups]}{'next_index'};
}
if(!Win32::Lanman::NetGroupAdd("\\\\testserver", "testgroup", "test group comment"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetGroupAddUser("\\\\testserver", "testgroup", "testuser"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetLocalGroupDel("\\\\testserver", "testgroup"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetLocalGroupDelMembers("\\\\testserver", "testgroup", "testuser"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetGroupEnum("\\\\testserver", \@groups))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $group (@groups)
{
print "${$group}{'name'}\t${$group}{'comment'}\t${$group}{'group_id'}\t${$group}{'attributes'}\n";
}
if(!Win32::Lanman::NetGroupGetInfo("\\\\testserver", "testgroup", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$info{'name'}\t$info{'comment'}\t$info{'group_id'}\t$info{'attributes'}\n";
if(!Win32::Lanman::NetGroupGetUsers("\\\\testserver", "testgroup", \@users))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $user (@users)
{
#don't print these binary data
#print "${$user}{'sid'}\n";
print "${$user}{'name'}\t${$user}{'attributes'}\n";
}
if(!Win32::Lanman::NetGroupSetInfo("\\\\testserver", "testgroup", {'name' => 'newtestgrp', 'comment' => 'comment for testgroup'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetGroupSetUsers("\\\\testserver", "testgroup", ['user1', 'user2', 'user3']))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetLocalGroupAdd("\\\\testserver", "testgroup", "test group comment"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetLocalGroupAddMember("\\\\testserver", "testgroup", $sid))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::NetLocalGroupAddMembers("testserver",
"testgroup",
['glb_grp', 'domain\glb_grp', 'user', 'domain\user'])
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::LsaLookupNames("testserver",
['glb_grp', 'domain\glb_grp', 'user', 'domain\user'],
\@sids))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@members = map { ${$_}{sid} } @sids;
unless(Win32::Lanman::NetLocalGroupAddMembersBySid("testserver", "testgroup", \@members))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::NetLocalGroupDel("testserver", "testgroup"))
{
print 'Sorry, something went wrong; in ( Win32::Lanman::NetLocalGroupDel ) error: ';
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetLocalGroupDelMember("\\\\testserver", "testgroup", $sid))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::NetLocalGroupDelMembers("testserver", "testgroup",
['glb_grp', 'domain\glb_grp', 'user', 'domain\user'])
)
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::LsaLookupNames("testserver",
['glb_grp', 'domain\glb_grp', 'user', 'domain\user'],
\@sids))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@members = map { ${$_}{sid} } @sids;
unless(Win32::Lanman::NetLocalGroupDelMembersBySid("testserver", "testgroup", \@members))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::NetLocalGroupEnum("testserver", \@groups))
{
print 'Sorry, something went wrong in (Win32::Lanman::NetLocalGroupEnum) ; error: ';
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $group (@groups)
{
print "${$group}{'name'}\t${$group}{'comment'}\n";
}
if(!Win32::Lanman::NetLocalGroupGetInfo("\\\\testserver", "testgroup", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$info{'name'}\t$info{'comment'}\n";
if(!Win32::Lanman::NetLocalGroupGetMembers("\\\\testserver", "testgroup", \@members))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $member (@members)
{
#don't print these binary data
#print "${$member}{'sid'}\n";
print "${$member}{'domainandname'}\t${$member}{'sidusage'}\n";
}
unless(Win32::Lanman::NetLocalGroupSetInfo("testserver",
"testgroup",
{'name' => 'newtestgrp',
'comment' => 'comment for testgroup'}
)
)
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::NetLocalGroupSetMembers("testserver",
"testgroup",
['user1',
'testdomain\group1',
'testdomain\user1']
)
)
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
unless(Win32::Lanman::LsaLookupNames("testserver",
['user1', 'testdomain\user1', 'testdomain\group1'],
\@sids))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@members = map { ${$_}{sid} } @sids;
unless(Win32::Lanman::NetLocalGroupSetMembersBySid("testserver", "testgroup", \@members))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::I_NetLogonControl("\\\\testserver", &NETLOGON_CONTROL_QUERY, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Replicates the sam changes of \\testserver with the PDC. \\testserver must be a BDC.
if(!Win32::Lanman::I_NetLogonControl("\\\\testserver", &NETLOGON_CONTROL_REPLICATE, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Synchronizes the sam of \\testserver with the PDC. \\testserver must be a PDC or BDC.
if(!Win32::Lanman::I_NetLogonControl("\\\\testserver", &NETLOGON_CONTROL_SYNCHRONIZE, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Forces to send a synchronize request to all BDC's. \\testserver must be a PDC.
if(!Win32::Lanman::I_NetLogonControl("\\\\testserver", &NETLOGON_CONTROL_PDC_REPLICATE, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::I_NetLogonControl2("\\\\testserver", &NETLOGON_CONTROL_REDISCOVER, "testdomain", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Queries the status of the secure channel for domain testdomain on server \\testserver.
if(!Win32::Lanman::I_NetLogonControl2("\\\\testserver", &NETLOGON_CONTROL_TC_QUERY, "testdomain", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Informs the server \\testserver about a new transport coming up.
if(!Win32::Lanman::I_NetLogonControl2("\\\\testserver", &NETLOGON_CONTROL_TRANSPORT_NOTIFY, '', \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Retrieves which trusted domain will log on user testuser. The command will be excuted on server \\testserver.
if(!Win32::Lanman::I_NetLogonControl2("\\\\testserver", &NETLOGON_CONTROL_FIND_USER, "testuser", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlQuery("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlReplicate("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlSynchronize("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlPdcReplicate("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlRediscover("\\\\testserver", "testdomain", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlTCQuery("\\\\testserver", "testdomain", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlTransportNotify("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LogonControlFindUser("\\\\testserver", "testuser", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetEnumerateTrustedDomains("\\\\testserver", \@domains))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $domain (@domains)
{
print "$domain\n";
}
if(!Win32::Lanman::I_NetGetDCList("\\\\testserver", "testdomain", \@servers))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $server (@servers)
{
print "$server\n";
}
if(!Win32::Lanman::NetMessageBufferSend("\\\\testserver", "user1", "computer1", "this is a message"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetMessageNameAdd("\\\\testserver", "testuser1"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetMessageNameDel("\\\\testserver", "testuser1"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetMessageNameEnum("\\\\testserver", \@info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach (@info)
{
print "$_\n";
}
if(!Win32::Lanman::NetMessageNameEnum("\\\\testserver", "user1", \$info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $info;
The following are equivalent, Win32::Lanman::LsaQueryInformationPolicy(``'', &PolicyAuditFullQueryInformation, \%info); and Win32::Lanman::LsaQueryAuditFullPolicy(``'', \%info);
Please use the second form , it is less prone to error.
Avoid using EnumPrivilegeAccounts. Use LsaEnumerateAccountsWithUserRight instead.
if(!Win32::Lanman::LsaQueryInformationPolicy("\\\\testserver", &PolicyAuditLogInformation, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
#events to audit $options[AuditCategorySystem] = &POLICY_AUDIT_EVENT_UNCHANGED; $options[AuditCategoryLogon] = &POLICY_AUDIT_EVENT_SUCCESS; $options[AuditCategoryObjectAccess] = &POLICY_AUDIT_EVENT_FAILURE; $options[AuditCategoryPrivilegeUse] = &POLICY_AUDIT_EVENT_NONE; $options[AuditCategoryDetailedTracking] = &POLICY_AUDIT_EVENT_SUCCESS | &POLICY_AUDIT_EVENT_FAILURE; $options[AuditCategoryPolicyChange] = &POLICY_AUDIT_EVENT_NONE; $options[AuditCategoryAccountManagement] = &POLICY_AUDIT_EVENT_NONE; # only valid in nt 5 $options[AuditCategoryDirectoryServiceAccess] = &POLICY_AUDIT_EVENT_NONE; $options[AuditCategoryAccountLogon] = &POLICY_AUDIT_EVENT_NONE;
%info = ('auditingmode' => 1, # turn on auditing
'eventauditingoptions' => \@options # events to audit
);
if(!Win32::Lanman::LsaSetInformationPolicy("\\\\testserver", PolicyAuditEventsInformation, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryAuditLogPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LsaQueryAuditEventsPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "auditingmode=$info{auditingmode}\n";
print "maximumauditeventcount=$info{maximumauditeventcount}\n";
print "eventauditingoptions:\n";
if($info{maximumauditeventcount} > 0)
{
$options = $info{eventauditingoptions};
foreach $option (@$options)
{
print "\t$option\n";
}
}
#events to audit $options[AuditCategorySystem] = &POLICY_AUDIT_EVENT_UNCHANGED; $options[AuditCategoryLogon] = &POLICY_AUDIT_EVENT_SUCCESS; $options[AuditCategoryObjectAccess] = &POLICY_AUDIT_EVENT_FAILURE; $options[AuditCategoryPrivilegeUse] = &POLICY_AUDIT_EVENT_NONE; $options[AuditCategoryDetailedTracking] = &POLICY_AUDIT_EVENT_SUCCESS | &POLICY_AUDIT_EVENT_FAILURE; $options[AuditCategoryPolicyChange] = &POLICY_AUDIT_EVENT_NONE; $options[AuditCategoryAccountManagement] = &POLICY_AUDIT_EVENT_NONE; # only valid in nt 5 $options[AuditCategoryDirectoryServiceAccess] = &POLICY_AUDIT_EVENT_NONE; $options[AuditCategoryAccountLogon] = &POLICY_AUDIT_EVENT_NONE;
%info = ('auditingmode' => 1, # turn on auditing
'eventauditingoptions' => \@options # events to audit
);
if(!Win32::Lanman::LsaSetAuditEventsPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryPrimaryDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "name=$info{name}\n";
print "sid=", unpack("H" . 2 * length($info{sid}), $info{sid}), "\n";
if(!Win32::Lanman::LsaQueryPrimaryDomainPolicy("\\\\testserver1", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "name=$info{name}\n";
print "sid=", unpack("H" . 2 * length($info{sid}), $info{sid}), "\n";
if(!Win32::Lanman::LsaSetPrimaryDomainPolicy("\\\\testserver2", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryPdAccountPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LsaQueryAccountDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "domainname=$info{domainname}\n";
print "domainsid=", unpack("H" . 2 * length($info{domainsid}), $info{domainsid}), "\n";
if(!Win32::Lanman::LsaQueryAccountDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "domainname=$info{domainname}\n";
print "domainsid=", unpack("H" . 2 * length($info{domainsid}), $info{domainsid}), "\n";
$info{domainname} = 'testserver2';
if(!Win32::Lanman::LsaSetAccountDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryServerRolePolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
%info = (serverrole => &PolicyServerRoleBackup); if(!Win32::Lanman::LsaQueryServerRolePolicy(``\\\\testserver'', \%info)) { print ``Sorry, something went wrong; error: ''; # get the error code print Win32::Lanman::GetLastError(); exit 1; }
if(!Win32::Lanman::LsaQueryReplicaSourcePolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
$info{replicasource} = "\\\\testserver2";
if(!Win32::Lanman::LsaSetReplicaSourcePolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryDefaultQuotaPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LsaQueryDefaultQuotaPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
$info{minimumworkingsetsize} *= 2;
if(!Win32::Lanman::LsaSetDefaultQuotaPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryAuditFullPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LsaSetAuditFullPolicy("\\\\testserver", {shutdownonfull => 1}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryDnsDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "name=$info{name}\n";
print "dnsdomainname=$info{dnsdomainname}\n";
print "dnsforestname=$info{dnsforestname}\n";
print "guid=", unpack("H" . 2 * length($info{guid}), $info{guid}), "\n";
print "sid=", unpack("H" . 2 * length($info{sid}), $info{sid}), "\n";
if(!Win32::Lanman::LsaQueryDnsDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
#$info{dnsdomainname} = ...
#$info{dnsforestname} = ...
if(!Win32::Lanman::LsaSetDnsDomainPolicy("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaEnumerateTrustedDomains("", \@domains))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $domain(@domains)
{
print "name=${$domain}{name}\t";
print "sid=" . unpack("H" . 2 * length(${$domain}{sid}), ${$domain}{sid}) . "\n";
}
Enumerates all trusted domains of the domain testdomain.
if(!Win32::Lanman::NetGetDCName("", "testdomain", \$pdcname))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaEnumerateTrustedDomains($pdcname, \@domains))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $domain(@domains)
{
print "name=${$domain}{name}\t";
print "sid=" . Win32::Lanman::SidToString(${$domain}{sid}) . "\n";
}
Enumerate all Trusted domains for your workstation
if(!Win32::Lanman::LsaEnumerateTrustedDomains("", \@domains))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
foreach my $domain (@domains)
{
next
unless Win32::Lanman::NetGetAnyDCName("", ${$domain}{name},\$prim_dom_dcname);
print "name=${$domain}{name}, anydc=$prim_dom_dcname\n";
next
unless Win32::Lanman::LsaEnumerateTrustedDomains($prim_dom_dcname, \@trusts);
foreach $trust(@trusts)
{
next
unless Win32::Lanman::NetGetAnyDCName($prim_dom_dcname, ${$trust}{name}, \$dcname);
print "$prim_dom_dcname Trusts name=${$trust}{name}, anydc=$dcname\n";
}
}
@accounts = ('user1', 'user2', 'group1', 'testdomain\\group2');
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", @accounts, \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $info (@infos)
{
print "name=", $accounts[$count++], "\n";
@keys = sort keys %$info;
foreach $key(@keys)
{
if($key eq "domainsid" || $key eq "sid")
{
print "$key=" . unpack("H" . 2 * length(${$info}{$key}), ${$info}{$key}) . "\n";
}
else
{
print "$key=${$info}{$key}\n";
}
}
}
@sids = (
pack("C12", 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), #everyone
pack("C12", 1, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0), #local
pack("C12", 1, 1, 0, 0, 0, 0, 0, 5, 2, 0, 0, 0), #network
pack("C12", 1, 1, 0, 0, 0, 0, 0, 5, 3, 0, 0, 0), #batch
pack("C12", 1, 1, 0, 0, 0, 0, 0, 5, 6, 0, 0, 0), #service
pack("C12", 1, 1, 0, 0, 0, 0, 0, 5, 3, 0, 0, 0), #batch
pack("C16", 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0 ,0), #administrators
pack("C16", 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 33, 2, 0 ,0), #users
pack("C16", 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 34, 2, 0 ,0) #guests
);
if(!Win32::Lanman::LsaLookupSids("\\\\testserver", \@sids, \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $info (@infos)
{
print "sid=" . unpack("H" . 2 * length($sids[$count]), $sids[$count++]) . "\n";
@keys = sort keys %$info;
foreach $key(@keys)
{
if($key eq "domainsid")
{
print "$key=" . unpack("H" . 2 * length(${$info}{$key}), ${$info}{$key}) . "\n";
}
else
{
print "$key=${$info}{$key}\n";
}
}
}
if(!Win32::Lanman::LsaEnumerateAccountsWithUserRight("\\\\testserver", &SE_NETWORK_LOGON_NAME, \@sids))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupSids("\\\\testserver", \@sids, \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $info (@infos)
{
@keys = sort keys %$info;
foreach $key(@keys)
{
if($key eq "domainsid" || $key eq "sid")
{
print "$key=" . unpack("H" . 2 * length(${$info}{$key}), ${$info}{$key}) . "\n";
}
else
{
print "$key=${$info}{$key}\n";
}
}
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testuser'], \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaEnumerateAccountRights("\\\\testserver", ${$infos[0]}{sid}, \@privileges))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $priv(@privileges)
{
print "$priv\n";
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testuser'], \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaAddAccountRights("\\\\testserver", ${$infos[0]}{sid},
[&SE_BACKUP_NAME, &SE_RESTORE_NAME, &SE_SHUTDOWN_NAME, &SE_DEBUG_NAME]))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testuser'], \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaRemoveAccountRights("\\\\testserver", ${$infos[0]}{sid},
[&SE_BACKUP_NAME, &SE_RESTORE_NAME, &SE_SHUTDOWN_NAME, &SE_DEBUG_NAME]))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
Removes all privileges from the user testuser on server \\testserver.
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testuser'], \@infos))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaRemoveAccountRights("\\\\testserver", ${$infos[0]}{sid}, [], 1))
{
print "Sorry, something went wrong; error: ";
# get the error code
#print
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryTrustedDomainInfo("\\\\testserver", ${$domain[0]}{domainsid}, &TrustedPasswordInformation, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "password=" . unpack("H" . 2 * length($info{password}), $info{password}) . "\n";
print "oldpassword=" . unpack("H" . 2 * length($info{oldpassword}), $info{oldpassword}) . "\n";
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaSetTrustedDomainInformation("\\\\testserver", ${$domain[0]}{domainsid},
&TrustedPasswordInformation,
{ password => 'newpassword'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaSetTrustedDomainInfo("\\\\testserver", ${$domain[0]}{domainsid},
&TrustedPasswordInformation,
{ password => 'newpassword'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryTrustedDomainNameInfo("\\\\testserver", ${$domain[0]}{domainsid}, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaSetTrustedDomainNameInfo("\\\\testserver", ${$domain[0]}{domainsid}, {name => 'testdomain'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryTrustedPosixOffsetInfo("\\\\testserver", ${$domain[0]}{domainsid}, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaSetTrustedPosixOffsetInfo("\\\\testserver", ${$domain[0]}{domainsid},
{offset => 123456}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaQueryTrustedPasswordInfo("\\\\testserver", ${$domain[0]}{domainsid}, \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "password=" . unpack("H" . 2 * length($info{password}), $info{password}) . "\n";
print "oldpassword=" . unpack("H" . 2 * length($info{oldpassword}), $info{oldpassword}) . "\n";
if(!Win32::Lanman::LsaLookupNames("\\\\testserver", ['testdomain'], \@domain))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaSetTrustedPasswordInfo("\\\\testserver", ${$domain[0]}{domainsid},
{ password => 'newpassword'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::LsaRetrievePrivateData("\\\\testserver", "\$MACHINE.ACC", \$data))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $data;
if(!Win32::Lanman::LsaStorePrivateData("\\\\testserver", "\$MACHINE.ACC", 'new_machine_pwd'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::GrantPrivilegeToAccount("\\\\testserver", &SE_SHUTDOWN_NAME,
["testuser1", "testuser2", "testgroup"]))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::RevokePrivilegeToAccount("\\\\testserver", &SE_SERVICE_LOGON_NAME,
["testuser1", "testuser2", "testgroup"]))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::EnumAccountPrivileges("\\\\testserver", "testuser", \@privileges))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach (@privileges)
{
print "$_\n";
}
if(!Win32::Lanman::EnumAccountPrivileges("\\\\testserver", &SE_INTERACTIVE_LOGON_NAME, \@accounts))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach (@accounts)
{
print "$_\n";
}
if(!Win32::Lanman::NetReplExportDirAdd("\\\\testserver",
{'dirname' => "testexportdir",
'integrity' => &REPL_INTEGRITY_FILE,
'extent' => &REPL_EXTENT_TREE}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplExportDirDel("\\\\testserver", "testexportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplExportDirEnum("\\\\testserver", \@directories))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $directory (@directories)
{
@keys = sort keys %$directory;
foreach $key (@keys)
{
print "$key=${$directory}{$key}\n";
}
}
if(!Win32::Lanman::NetReplExportDirGetInfo("\\\\testserver", "testexportdir", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key (@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetReplExportDirLock("\\\\testserver", "testexportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplExportDirSetInfo("\\\\testserver", "testexportdir",
{'dirname' => "testexportdir",
'integrity' => &REPL_INTEGRITY_FILE,
'extent' => &REPL_EXTENT_FILE}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplExportDirUnlock("\\\\testserver", "testexportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Sets the lock counter to zero for the replicated directory testexportdir on server \\testserver.
if(!Win32::Lanman::NetReplExportDirUnlock("\\\\testserver", "testexportdir", REPL_UNLOCK_FORCE))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplGetInfo("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key (@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetReplImportDirAdd("\\\\terstserver", "testimportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplImportDirDel("\\\\testserver", "testimportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplImportDirEnum("\\\\testserver", \@directories))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $directory (@directories)
{
@keys = keys %$directory;
foreach $key (@keys)
{
print "$key=${$directory}{$key}\n";
}
}
if(!Win32::Lanman::NetReplImportDirGetInfo("\\\\testserver", "testimportdir", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key (@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetReplImportDirLock("\\\\testserver", "testimportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplImportDirUnlock("\\\\testserver", "testimportdir"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Sets the lock counter to zero for the replicated directory testimportdir on server \\testserver.
if(!Win32::Lanman::NetReplImportDirUnlock("\\\\testserver", "testimportdir", REPL_UNLOCK_FORCE))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetReplSetInfo("\\\\testserver",
{role => REPL_ROLE_BOTH,
exportpath => "c:\\winnt\\system32\\repl\\export",
exportlist => 'testexpdomain',
importpath => "c:\\winnt\\system32\\repl\\import",
importlist => 'testimpdomain',
logonusername => '',
interval => 10,
pulse => 2,
guardtime => 5,
random => 120}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetScheduleJobAdd("\\\\testserver",
{jobtime => 12 * 3600 * 1000,
daysofmonth => 0, daysofmonth => 0,
daysofweek => 0,
flags => 0,
command => "winfile.exe"}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $info{jobid};
if(!Win32::Lanman::NetScheduleJobDel("\\\\testserver", 5, 10))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetScheduleJobEnum("\\\\testserver", \@jobs))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $job (@jobs)
{
@keys = keys %$job;
foreach $key (@keys)
{
print "$key=${$job}{$key}\n";
}
}
if(!Win32::Lanman::NetScheduleJobGetInfo("\\\\testserver", 5, \%job))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %job;
foreach $key (@keys)
{
print "$key=$job{$key}\n";
}
$type can be any of the constants SV_TYPE_*. e.g. SV_TYPE_SQLSERVER , SV_TYPE_TERMINALSERVER , SV_TYPE_NT .
These can also be combined using |. To get all SQL servers or terminal servers user $type = SV_TYPE_SQLSERVER | SV_TYPE_TERMINALSERVER
if(!Win32::Lanman::NetServerDiskEnum("\\\\testserver", \@disks))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $disk (@disks)
{
print "$disk\n";
}
if(!Win32::Lanman::NetServerEnum("\\\\testserver", "testdomain", SV_TYPE_NT, \@info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $server (@info)
{
@keys = keys %$server;
foreach $key(@keys)
{
print "$key=${$server}{$key}\n";
}
}
if(!Win32::Lanman::NetServerGetInfo("\\\\testserver", \%info, 1))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
Retrieves only basic information about the server \\testserver.
if(!Win32::Lanman::NetServerGetInfo("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetServerGetInfo("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
$info{'hidden'} = 1; $info{'userpath'} = ``c:\\users'';
if(!Win32::Lanman::NetServerSetInfo("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetServerTransportAdd("\\\\testserver",
{'domain' => 'testdomain',
'networkaddress' => '000000000000',
'numberofvcs' => 0,
'transportaddress' => 'TESTSERVER',
'transportaddresslength' => length('TESTSERVER'),
'transportname' => "\\Device\\NetBT_NdisWan7"
}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetServerTransportDel("\\\\testserver",
{'domain' => 'testdomain',
'networkaddress' => '000000000000',
'numberofvcs' => 0,
'transportaddress' => 'TESTSERVER',
'transportaddresslength' => length('TESTSERVER'),
'transportname' => "\\Device\\NetBT_NdisWan7"
}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetServerTransportEnum("\\\\testserver", \@info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $server (@info)
{
@keys = keys %$server;
foreach $key(@keys)
{
print "$key=#${$server}{$key}#\n";
}
}
if(!Win32::Lanman::NetSessionDel("\\\\testserver", '', ''))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Ends the session on server \\testserver to client \\testclient for user testuser.
if(!Win32::Lanman::NetSessionDel("\\\\testserver", "\\\\testclient", "testuser"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetSessionEnum("\\\\testserver", "", "", \@sessions))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $session (@sessions)
{
@keys = keys %$session;
foreach $key(@keys)
{
print "$key=#${$session}{$key}#\n";
}
}
Provides information about the current sessions for client \\testclient and user testuser on server \\testserver.
if(!Win32::Lanman::NetSessionEnum("\\\\testserver", "\\\\testclient", "testuser", \@sessions))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $session (@sessions)
{
@keys = keys %$session;
foreach $key (@keys)
{
print "$key=#${$session}{$key}#\n";
}
}
if(!Win32::Lanman::NetSessionGetInfo("\\\\testserver", "\\\\testclient", "", \%session))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %session;
foreach $key (@keys)
{
print "$key=$session{$key}\n";
}
In the following section on shares. Information about a share is stored in a hash (%shareinfo). The following are valid keys: netname, type, remark, permissions, max_uses, current_uses, path, passwd and security_descriptor (which is has a binary value)
$secdesc = ...
if(!Win32::Lanman::NetShareAdd("\\\\testdfsserver",
{'netname' => 'testshare', # share name
type => Win32::Lanman::STYPE_DISKTREE, # share type
remark => 'remark for testshare', # remark
permissions => 0, # only used for share level security
max_uses => 5, # number of users can connect
current_uses => 0, # unused
path => 'c:\test', # physical share path
passwd => 'password', # password
security_descriptor => $secdesc})) # sec. descriptor if you need security
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetShareCheck("\\\\testserver", "c:\\test", \$type))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $type;
if(!Win32::Lanman::NetShareDel("\\\\testserver", "testshare"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetShareEnum("\\\\testserver", \@shares))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $share (@shares)
{
print "${$share}{'netname'}\n";
print "${$share}{'type'}\n";
print "${$share}{'remark'}\n";
print "${$share}{'permissions'}\n";
print "${$share}{'max_uses'}\n";
print "${$share}{'current_uses'}\n";
print "${$share}{'path'}\n";
print "${$share}{'passwd'}\n";
#don't print these binary data
#print "${$share}{'security_descriptor'}\n";
}
if(!Win32::Lanman::NetShareGetInfo("\\\\testserver", "testshare", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$info{'netname'}\n";
print "$info{'type'}\n";
print "$info{'remark'}\n";
print "$info{'permissions'}\n";
print "$info{'max_uses'}\n";
print "$info{'current_uses'}\n";
print "$info{'path'}\n";
print "$info{'passwd'}\n";
#don't print these binary data
#print "$info{'security_descriptor'}\n";
unless(Win32::Lanman::NetShareSetInfo("\\\\testserver", "testshare",
{'remark' => 'new remark', 'max_uses' => 5}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetConnectionEnum("\\\\testserver", "testshare", \%conns))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $conn(@conns)
{
foreach $key(sort keys %$conn)
{
print "$key=${$conn}{$key}\n";
}
}
Gets all connections made from computer testcomputer to the server testserver.
if(!Win32::Lanman::NetConnectionEnum("\\\\testserver", "\\\\testcomputer", \%conns))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $conn(@conns)
{
foreach $key(sort keys %$conn)
{
print "$key=${$conn}{$key}\n";
}
}
Retrieves operating statistics for the service server on server \\testserver.
if(!Win32::Lanman::NetStatisticsGet("\\\\testserver", "SERVER", \%statistics))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %statistics;
foreach $key (@keys)
{
print "$key=$statistics{$key}\n";
}
Retrieves operating statistics for the service workstation on server \\testserver.
if(!Win32::Lanman::NetStatisticsGet("\\\\testserver", "WORKSTATION", \%statistics))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %statistics;
foreach $key (@keys)
{
print "$key=$statistics{$key}\n";
}
NetWkstaUserGetInfo(\@info)NetWkstaUserSetInfo(\@info)
if(!Win32::Lanman::NetWkstaGetInfo("\\\\testserver", \%info, 1))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key (@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetWkstaSetInfo($server, {'char_wait' => 3600,
'collection_time' => 250,
'maximum_collection_count' => 16,
'keep_conn' => 600,
'sess_timeout' => 45,
'siz_char_buf' => 512}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetWkstaTransportAdd("\\testserver"
{'number_of_vcs' => 0,
'transport_address' => '000000000000',
'transport_name' => "\\Device\\NetBT_NdisWan7",
'quality_of_service' => 0xffff}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetWkstaTransportDel("\\\\testserver", "\\Device\\NetBT_NdisWan7", USE_FORCE))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetWkstaTransportEnum("\\\\testserver", \@info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $transport (@info)
{
@keys = keys %$transport;
foreach $key (@keys)
{
print "$key=#${$transport}{$key}#\n";
}
}
NetWkstaUserGetInfo(\@info)
if(!Win32::Lanman::NetWkstaUserGetInfo(\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key (@keys)
{
print "$key=$info{$key}\n";
}
NetWkstaUserSetInfo(\@info)
if(!Win32::Lanman::NetWkstaUserSetInfo({'username' => 'testuser',
'logon_domain' => 'testdomain',
'oth_domains' => 'test_oth_domain',
'logon_server' => 'logonserver'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetWkstaUserEnum("\\\\testserver", \@info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $user (@info)
{
@keys = keys %$user;
foreach $key (@keys)
{
print "$key=#${$user}{$key}#\n";
}
}
if(!Win32::Lanman::NetRemoteTOD("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys %info;
foreach $key(@keys)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::NetRemoteComputerSupports("\\\\testserver",
&SUPPORTS_REMOTE_ADMIN_PROTOCOL |
&SUPPORTS_RPC | &SUPPORTS_SAM_PROTOCOL |
&SUPPORTS_UNICODE, \$supported))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "RAP is", ($supported & &SUPPORTS_REMOTE_ADMIN_PROTOCOL) ? "" : " not", " supported\n"; print "RPC is", ($supported & &SUPPORTS_RPC) ? "" : " not", " supported\n"; print "SAM is", ($supported & &SUPPORTS_SAM_PROTOCOL) ? "" : " not", " supported\n"; print "UNICODE is", ($supported & &SUPPORTS_UNICODE) ? "" : " not", " supported\n";
NetUseAdd(\%info)NetUseEnum(\@info)
NetUseAdd(\%info)
if(!Win32::Lanman::NetUseAdd({remote => "\\\\testserver\\ipc\$",
password => "testpass",
username => "testuser",
domain => "testdomain",
asg_type => &USE_IPC}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
connects drive h: to \\testserver\testshare.
if(!Win32::Lanman::NetUseAdd({remote => "\\\\testserver\\testshare",
local => "h:",
asg_type => &USE_DISKDEV}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
connects port lpt3: to \\testserver\testprint.
if(!Win32::Lanman::NetUseAdd({remote => "\\\\testserver\\testprint",
local => "lpt3:",
asg_type => &USE_SPOOLDEV}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUseDel("\\\\testserver\\testshare"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Deletes the connection to drive h:. If there are open files, the connection will be closed.
if(!Win32::Lanman::NetUseDel("h:", &USE_FORCE))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
NetUseEnum(\@info)
if(!Win32::Lanman::NetUseEnum(\@uses))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $use (@uses)
{
foreach (sort keys %$use)
{
print "$_=${$use}{$_}\n";
}
}
if(!Win32::Lanman::NetUseGetInfo('\\\\testserver\\testshare', \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach (sort keys %info)
{
print "$_=$info{$_}\n";
}
In this section, you cannot specify a domain name for the server parameter. Instead to affect domain accounts, obtain the PDC, using NetGetDCName, and then make the calls against this server.
To Change the password for a domain account run the command on the PDC (not a BDC!).
To change a user's password without knowing the old password use NetUserSetInfo or NetUserSetProp.
To do this you need to have admin rights to perform the task.
$location should be either a domainname (clear text) or a servername ('\\server')
for local machine accounts.
Note in this function should you desire to create a local machine account you must use the ``\\\\my_machine'' format for $location; the module does not insert the '\\' for you for this function!
if(!Win32::Lanman::NetUserAdd("\\\\testserver", {'name' => 'testuser',
'password' => 'testpassword',
'home_dir' => '\\\\testserver\\testshare',
'comment' => 'test users comment',
'flags' => UF_ACCOUNTDISABLE | UF_PASSWD_CANT_CHANGE | UF_TEMP_DUPLICATE_ACCOUNT,
'script_path' => '\\\\testserver\\testshare\\logon_script.bat',
'full_name' => 'test users full name',
'usr_comment' => 'test users usr comment',
'parms' => 'test users parameters',
'workstations' => 'comp0001,comp0002,comp0003,comp0004,comp0005,comp0006,comp0007,comp0008',
'profile' => '\\\\testserver\\testshare\\profile_dir',
'home_dir_drive' => 'Y:',
'acct_expires' => time() + 3600 * 24,
'country_code' => 49,
'code_page' => 850,
'logon_hours' => pack("b168", "000000001111111100000000" x 7),
'password_expired' => 1}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUserChangePassword("testdomain", 'testuser', 'old_password', 'new_password'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Changes user testuser's password on the server \\testserver.
if(!Win32::Lanman::NetUserChangePassword("\\\\testserver", 'testuser', 'old_password', 'new_password'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUserCheckPassword("testdomain", 'testuser', 'testpass'))
{
print "Password testpass for user testuser in domain testdomain isn't valid; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "Password testpass for user testuser in domain testdomain is valid.";
Checks if user testuser's password testpass on the server \\testserver is valid or not.
if(!Win32::Lanman::NetUserCheckPassword("\\\\testserver", 'testuser', 'testpass'))
{
print "Password testpass for user testuser on server \\\\testserver isn't valid; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "Password testpass for user testuser on server \\\\testserver is valid.";
if(!Win32::Lanman::NetUserDel("\\\\testserver", 'testuser'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUserEnum("testdomain", 0, \@users))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $user (@users)
{
$hours = unpack("b168", ${$user}{'logon_hours'});
print "${$user}{'name'}\n";
print "${$user}{'comment'}\n";
print "${$user}{'usr_comment'}\n";
print "${$user}{'full_name'}\n";
print "${$user}{'password_age'}\n";
print "${$user}{'priv'}\n";
print "${$user}{'home_dir'}\n";
print "${$user}{'flags'}\n";
print "${$user}{'script_path'}\n";
print "${$user}{'auth_flags'}\n";
print "${$user}{'parms'}\n";
print "${$user}{'workstations'}\n";
print "${$user}{'last_logon'}\n";
print "${$user}{'last_logoff'}\n";
print "${$user}{'acct_expires'}\n";
print "${$user}{'max_storage'}\n";
print "${$user}{'units_per_week'}\n";
print "$hours\n";
print "${$user}{'bad_pw_count'}\n";
print "${$user}{'num_logons'}\n";
print "${$user}{'logon_server'}\n";
print "${$user}{'country_code'}\n";
print "${$user}{'code_page'}\n";
print "${$user}{'user_id'}\n";
print "${$user}{'primary_group_id'}\n";
print "${$user}{'profile'}\n";
print "${$user}{'home_dir_drive'}\n";
print "${$user}{'password_expired'}\n";
}
Enums all user on server \\testserver. Only normal accounts will be enumerated.
if(!Win32::Lanman::NetUserEnum("\\\\testserver", &FILTER_NORMAL_ACCOUNT, \@users))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $user (@users)
{
$hours = unpack("b168", ${$user}{'logon_hours'});
print "${$user}{'name'}\n";
print "${$user}{'comment'}\n";
print "${$user}{'usr_comment'}\n";
print "${$user}{'full_name'}\n";
print "${$user}{'password_age'}\n";
print "${$user}{'priv'}\n";
print "${$user}{'home_dir'}\n";
print "${$user}{'flags'}\n";
print "${$user}{'script_path'}\n";
print "${$user}{'auth_flags'}\n";
print "${$user}{'parms'}\n";
print "${$user}{'workstations'}\n";
print "${$user}{'last_logon'}\n";
print "${$user}{'last_logoff'}\n";
print "${$user}{'acct_expires'}\n";
print "${$user}{'max_storage'}\n";
print "${$user}{'units_per_week'}\n";
print "$hours\n";
print "${$user}{'bad_pw_count'}\n";
print "${$user}{'num_logons'}\n";
print "${$user}{'logon_server'}\n";
print "${$user}{'country_code'}\n";
print "${$user}{'code_page'}\n";
print "${$user}{'user_id'}\n";
print "${$user}{'primary_group_id'}\n";
print "${$user}{'profile'}\n";
print "${$user}{'home_dir_drive'}\n";
print "${$user}{'password_expired'}\n";
}
if(!Win32::Lanman::NetUserGetGroups("testserver", "testuser", \@groups))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $group (@groups)
{
print "${$group}{'name'}\n";
}
if(!Win32::Lanman::NetUserGetInfo("testserver", "testuser", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
$hours = unpack("b168", $user{'logon_hours'});
print "$info{'name'}\n";
print "$info{'comment'}\n";
print "$info{'usr_comment'}\n";
print "$info{'full_name'}\n";
print "$info{'password_age'}\n";
print "$info{'priv'}\n";
print "$info{'home_dir'}\n";
print "$info{'flags'}\n";
print "$info{'script_path'}\n";
print "$info{'auth_flags'}\n";
print "$info{'parms'}\n";
print "$info{'workstations'}\n";
print "$info{'last_logon'}\n";
print "$info{'last_logoff'}\n";
print "$info{'acct_expires'}\n";
print "$info{'max_storage'}\n";
print "$info{'units_per_week'}\n";
print "$hours\n";
print "$info{'bad_pw_count'}\n";
print "$info{'num_logons'}\n";
print "$info{'logon_server'}\n";
print "$info{'country_code'}\n";
print "$info{'code_page'}\n";
print "$info{'user_id'}\n";
print "$info{'primary_group_id'}\n";
print "$info{'profile'}\n";
print "$info{'home_dir_drive'}\n";
print "$info{'password_expired'}\n";
if(!Win32::Lanman::NetUserGetLocalGroups("\\\\testserver", "testuser", &LG_INCLUDE_INDIRECT, \@groups))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $group (@groups)
{
print "${$group}{'name'}\n";
}
if(!Win32::Lanman::NetUserSetGroups("\\\\testserver", "testuser", ['domain users', 'testgroup1', 'testgroup2']))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUserSetInfo("\\\\testserver", "testuser",
{'name' => 'testuser',
'password' => 'testpassword',
'home_dir' => '\\\\testserver\\testshare',
'comment' => 'test users comment',
'flags' => UF_ACCOUNTDISABLE | UF_PASSWD_CANT_CHANGE | UF_TEMP_DUPLICATE_ACCOUNT,
'script_path' => '\\\\testserver\\testshare\\logon_script.bat',
'full_name' => 'test users full name',
'usr_comment' => 'test users usr comment',
'parms' => 'test users parameters',
'workstations' => 'comp0001,comp0002,comp0003,comp0004,comp0005,comp0006,comp0007,comp0008',
'profile' => '\\\\testserver\\testshare\\profile_dir',
'home_dir_drive' => 'Y:',
'acct_expires' => time() + 3600 * 24,
'country_code' => 49,
'code_page' => 850,
'logon_hours' => pack("b168", "000000001111111100000000" x 7),
'password_expired' => 1}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUserSetProp("\\\\testserver", "testuser",
{'name' => 'testuser',
'password' => 'testpassword',
'home_dir' => '\\\\testserver\\testshare',
'comment' => 'test users comment',
'flags' => UF_ACCOUNTDISABLE | UF_PASSWD_CANT_CHANGE | UF_TEMP_DUPLICATE_ACCOUNT,
'script_path' => '\\\\testserver\\testshare\\logon_script.bat',
'full_name' => 'test users full name',
'usr_comment' => 'test users usr comment',
'workstations' => 'comp0001,comp0002,comp0003,comp0004,comp0005,comp0006,comp0007,comp0008',
'acct_expires' => time() + 3600 * 24,
'logon_hours' => pack("b168", "000000001111111100000000" x 7),
'country_code' => 49,
'code_page' => 850,
'primary_group_id' => 513, # domain users
'profile' => '\\\\testserver\\testshare\\profile_dir',
'home_dir_drive' => 'Y:'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::NetUserModalsGet("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
@keys = keys(%info);
foreach $key(@keys)
{
print "$key: $info{$key}\n";
}
if(!Win32::Lanman::NetUserModalsGet("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Set minimum password age to 14 days, maximum password age to 2 months, minimum password length to 8 character
$info{'min_passwd_age'} = 14 * 3600 * 24;
$info{'max_passwd_age'} = 60 * 3600 * 24;
$info{'min_passwd_len'} = 8;
if(!Win32::Lanman::NetUserModalsSet("\\\\testserver", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
The Windows Networking functions offer a similar functionality like the NetUseXXX functions and some more.
WNetAddConnection(\%useinfo)
WNetAddConnection(\%useinfo)
$info{type} = &RESOURCETYPE_DISK;
$info{localname} = "z:";
$info{remotename} = "\\\\testserver\\testshare";
if(!Win32::Lanman::WNetAddConnection(\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Connects the local device x: to the share testshare on server \\testserver. The connection will be established with credentials from user testuser in the domain testdomain and the password testpass. The connection will be remembered if the user logs on again.
$info{type} = &RESOURCETYPE_DISK;
$info{localname} = "x:";
$info{remotename} = "\\\\testserver\\testshare";
$info{username} = "testdomain\\testuser";
$info{password} = "testpass";
$info{flags} = &CONNECT_UPDATE_PROFILE;
You may also specify a network provider name.
$info{provider} = "Microsoft Windows Network";
if(!Win32::Lanman::WNetAddConnection(\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Connects the local device lpt1: to the printer testprinter on server \\testserver.
$info{type} = &RESOURCETYPE_PRINT;
$info{localname} = "lpt1:";
$info{remotename} = "\\\\testserver\\testprinter";
if(!Win32::Lanman::WNetAddConnection(\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Connects to ipc$ on server \\testserver. The connection will be established with credentials from user testuser in the domain testdomain and the password testpass.
$info{type} = &RESOURCETYPE_ANY;
$info{remotename} = "\\\\testserver\\testprinter";
$info{password} = "testpass";
$info{flags} = &CONNECT_UPDATE_PROFILE;
if(!Win32::Lanman::WNetAddConnection(\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WNetCancelConnection("z:"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Cancels the connection to drive z:. The connection will be canceled even if there are still open files. The connection to z: won't be remembered furthermore.
if(!Win32::Lanman::WNetCancelConnection("z:", &CONNECT_UPDATE_PROFILE, 1))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Cancels the connection to \\testserver\testshare.
if(!Win32::Lanman::WNetCancelConnection("\\\\testserver\\testshare"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Cancels the connection to printer port lpt1:.
if(!Win32::Lanman::WNetCancelConnection("lpt1:"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WNetEnumResource(&RESOURCE_GLOBALNET, &RESOURCETYPE_ANY, 0, 0, \@info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $item (@info)
{
foreach $key (sort keys %$item)
{
print "$key=${$item}{$key}\n";
}
print "#" x 80;
}
Enumerates all resources in your network beginning at the top level. Be careful if you run this code in a bigger network. It may take a long time.
sub EnumNetRes
{
my @info;
my $level = $_[0];
return 0
unless Win32::Lanman::WNetEnumResource(&RESOURCE_GLOBALNET, &RESOURCETYPE_ANY, 0, $_[1], \@info);
foreach my $item (@info)
{
print " " x (2 * $level), "provider=#${$item}{provider}#\n";
print " " x (2 * $level), "localname=${$item}{localname}\n";
print " " x (2 * $level), "remotename=${$item}{remotename}\n";
print " " x (2 * $level), "comment=${$item}{comment}\n";
print " " x (2 * $level), sprintf "scope=0x%x\n", ${$item}{scope};
print " " x (2 * $level), sprintf "type=0x%x\n", ${$item}{type};
print " " x (2 * $level), sprintf "usage=0x%x\n", ${$item}{usage};
print "#" x 80;
EnumNetRes($level + 1, $item);
}
}
EnumNetRes();
print Win32::Lanman::WNetConnectionDialog() ?
"Connection established" : "Dialog canceled";
Shows a browsing dialog box and specifies some flags.
print Win32::Lanman::WNetConnectionDialog({flags => &CONNDLG_NOT_PERSIST | &CONNDLG_HIDE_BOX})
"Connection established" : "Dialog canceled";
Shows a browsing dialog box and specifies the server \\testserver and share testshare to connect.
print Win32::Lanman::WNetConnectionDialog({flags => &CONNDLG_NOT_PERSIST | &CONNDLG_HIDE_BOX,
remotename => "\\\\testserver\\testshare"})
"Connection established" : "Dialog canceled";
print Win32::Lanman::WNetDisconnectDialog() ?
"Connection removed" : "Dialog canceled";
Disconnects drive z: from the network resource. The disconnect is not forced and the connection to z: won't be remembered furthermore.
if(!Win32::Lanman::WNetDisconnectDialog({localname => "z:",
flags => &DISC_NO_FORCE | &DISC_UPDATE_PROFILE}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "Connection removed";
if(!Win32::Lanman::WNetGetConnection("z:", \$remote))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "z:=$remote";
Retrieves the name of the network resource associated with printer lpt1:.
if(!Win32::Lanman::WNetGetConnection("lpt1:", \$remote))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "lpt1:=$remote";
if(!Win32::Lanman::WNetGetNetworkInformation("Microsoft Windows Network", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::WNetGetProviderName(&WNNC_NET_LANMAN, \$provider))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $provider;
if(!Win32::Lanman::WNetGetResourceInformation({remotename => "\\\\testserver\\testshare\\testdir\\testfile.txt",
provider => "Microsoft Windows Network"},
\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::WNetGetResourceParent({remotename => "\\\\testserver\\testshare",
provider => "Microsoft Windows Network"},
\%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::WNetGetUniversalName("z:\\testdir\\testfile.txt", \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key(sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::WNetGetUser("z:", \$user))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $user;
if(!Win32::Lanman::WNetUseConnection({localname => "z:", remotename => "\\\\testserver\\testshare",
flags => &CONNECT_INTERACTIVE | &CONNECT_PROMPT,
type => &RESOURCETYPE_DISK}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Connects drive lpt1: to \\testserver\testprinter.
if(!Win32::Lanman::WNetUseConnection({localname => "lpt1:", remotename => "\\\\testserver\\testprinter",
type => &RESOURCETYPE_PRINT}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Throughout these functions, which are used to manage services, you can specify the default service database by replacing $servicedb with the empty string (or ``ServicesActive'').
Currently NT supports only the default database. If you specify an invalid database name, you'll get an error 1065 (database doesn't exist).
name : service name
display : service display name in control panel applet
type : service type
SERVICE_WIN32_OWN_PROCESS - the service file contains only one service
SERVICE_WIN32_SHARE_PROCESS - the service file contains more services
SERVICE_KERNEL_DRIVER - the service is a kernal driver
SERVICE_FILE_SYSTEM_DRIVER - the service is a file system driver
SERVICE_INTERACTIVE_PROCESS - the service can interact with the desktop,
must be or'ed with SERVICE_WIN32_OWN_PROCESS or
SERVICE_WIN32_SHARE_PROCESS;
if your service has to interact with the desktop, it has to
run with the localsystem account
start : when to start the service
SERVICE_BOOT_START - starts at boot time (device drivers)
SERVICE_SYSTEM_START - will be started by the IoInitSystem function
(device drivers)
SERVICE_AUTO_START - will be started by the service control manager
SERVICE_DEMAND_START - will be started by calling StartService
SERVICE_DISABLED - can't be started
control :
SERVICE_ERROR_IGNORE - errors will be logged, startup will be continued
SERVICE_ERROR_NORMAL - errors will be logged, startup will be continued,
message box will pop up
SERVICE_ERROR_SEVERE - errors will be logged, startup will be continued
if the last known good configuration is started,
otherwise the system is restarted with the last
known good configuration
SERVICE_ERROR_CRITICAL - errors will be logged, startup failes if the last
known good configuration is started, otherwise
the system is restarted with the last known
good configuration
filename: path to the executable which runs for the service
group : the load ordering group of which the service is a member
tagid : unique identifier for the service in the load order group;
only valid for device drivers
dependencies array : the service will not start until all services or
load ordering groups in the dependencies array are started
account : account name for the service to log on as; Should be specified as one of
'domain\username' for domain accounts
or '.\usr' or 'username' for machine accounts
or 'LocalSystem'
LocalSystem is not a real account, but instead species that the service will run with ``the system account''.
Note if type includes SERVICE_INTERACTIVE_PROCESS then account must => 'LocalSystem'.
The account chosen requires the logon as service privilege.
| password: password for account; | |
| if account =>LocalSystem, then password => '' |
SERVICE_WIN32 - win32 services SERVICE_DRIVER - kernel driver
Valid states are:
SERVICE_ACTIVE - active services SERVICE_INACTIVE - inactive services SERVICE_STATE_ALL - both of them
Note: Be careful when using this call, since if you revoke access to everyone, then nobody will be able to control the service. Also if you can grant the SERVICE_START and SERVICE_STOP rights to the everyone group, any people can start and stop your service (as default only administrators and power user can do this). Specify an empty string to use the default service database in $servicedb.
if(!Win32::Lanman::StartService("testserver", '', "schedule"))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::StopService("testserver", '', "schedule", \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
for $keyeach (sort keys %status) { print ``$key = $status{$key}\n''; }
if(!Win32::Lanman::PauseService("\\\\testserver", '', "schedule", \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
for $keyeach (sort keys %status)
{
print "$key = $status{$key}\n";
}
if(!Win32::Lanman::ContinueService("\\\\testserver", '', "schedule", \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
for $keyeach (sort keys %status)
{
print "$key = $status{$key}\n";
}
if(!Win32::Lanman::InterrogateService("\\\\testserver", '', "schedule", \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %status)
{
print "$key = $status{$key}\n";
}
if(!Win32::Lanman::ControlService("\\\\testserver", '', "schedule", &SERVICE_CONTROL_STOP, \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %status)
{
print "$key = $status{$key}\n";
}
Sends the value 130 to the service myservice on server \\testserver and prints the status flags.
if(!Win32::Lanman::ControlService("\\\\testserver", '', "myservice", 130, \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %status)
{
print "$key = $status{$key}\n";
}
if(!Win32::Lanman::GrantPrivilegeToAccount("\\\\testserver", "SeServiceLogonRight",
['testdomain\\testuser']) ||
!Win32::Lanman::CreateService("\\\\testserver", '', { name => 'myservice'
display => 'my first service',
type => &SERVICE_WIN32_OWN_PROCESS,
start => &SERVICE_AUTO_START,
control => &SERVICE_ERROR_NORMAL,
filename => "C:\\WINNT\\system32\\myservice.exe",
group => 'myservices',
account => 'testdomain\\testuser',
password => 'testpass'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Creates the next service myservice2 on server \\testserver. The display name is 'my next service'. The service logs on with the LocalSystem account (this is because account and password are missing, so LocalSystem is the default). The service has no dependencies or load ordering group. The service can have more than one service in the same file and it can interact with the desktop.
if(!Win32::Lanman::CreateService("\\\\testserver", '', { name => 'myservice2'
display => 'my next service',
type => &SERVICE_WIN32_SHARE_PROCESS |
&SERVICE_INTERACTIVE_PROCESS,
start => &SERVICE_DEMAND_START,
control => &SERVICE_ERROR_IGNORE,
filename => "C:\\WINNT\\system32\\mysrv_x.exe"}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Creates the 3rd service myservice3 on server \\testserver. The display name is 'my 3rd service'. The service logs on with the LocalSystem account. The service doesn't have dependencies or a load ordering group. The service may have more than one service in the same file.
if(!Win32::Lanman::CreateService("\\\\testserver", '', { name => 'myservice3'
display => 'my 3rd service',
type => &SERVICE_WIN32_SHARE_PROCESS,
start => &SERVICE_DEMAND_START,
control => &SERVICE_ERROR_IGNORE,
filename => "C:\\WINNT\\system32\\mysrv_x.exe",
account => 'LocalSystem',
password = ''}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Creates the 4th service myservice3 on server \\testserver. The display name is 'my 4th service'. The service logs on with the LocalSystem account. The service has dependencies (two services and one load ordering group). The service can interact with the desktop.
if(!Win32::Lanman::CreateService("\\\\testserver", '',
{ name => 'myservice4',
display => 'my 4th service',
type => &SERVICE_WIN32_OWN_PROCESS | &SERVICE_INTERACTIVE_PROCESS,
start => &SERVICE_DEMAND_START,
control => &SERVICE_ERROR_IGNORE,
filename => "C:\\WINNT\\system32\\mysrv4.exe",
dependencies => ['myservice2', 'myservice2', 'myservices']
}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::DeleteService("\\\\testserver", '', 'myservice'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::EnumServicesStatus("\\\\testserver", "",
&SERVICE_WIN32, &SERVICE_STATE_ALL, \@services))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $service (@services)
{
print "${$service}{name}\n";
foreach $key (sort keys %$service)
{
print "\t$key = ${$service}{$key}\n"
if $key ne 'name';
}
}
Enums the status of all active kernel drivers on server \\testserver.
if(!Win32::Lanman::EnumServicesStatus("\\\\testserver", "",
&SERVICE_DRIVER, &SERVICE_ACTIVE, \@services))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $service (@services)
{
print "${$service}{name}\n";
foreach $key (sort keys %$service)
{
print "\t$key = ${$service}{$key}\n"
if $key ne 'name';
}
}
if(!Win32::Lanman::EnumDependentServices("\\\\testserver", "", 'LanmanWorkstation', &SERVICE_STATE_ALL, \@services))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $service (@services)
{
print "${$service}{name}\n";
foreach $key (sort keys %$service)
{
print "\t$key = ${$service}{$key}\n"
if $key ne 'name';
}
}
if(!Win32::Lanman::ChangeServiceConfig("\\\\testserver", '', { name => 'myservice'
display => 'a new display name',
account => 'testdomain\\testuser',
password => 'testpass'}))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::GetServiceDisplayName("\\\\testserver", "", 'myservice', \$display))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $display;
if(!Win32::Lanman::GetServiceKeyName("\\\\testserver", "", 'my newest service', \$service))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $service;
if(!Win32::Lanman::LockServiceDatabase("\\\\testserver", "", \$lock))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
# do any stuff here...
if(!Win32::Lanman::UnlockServiceDatabase("\\\\testserver", "", $lock))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::QueryServiceLockStatus("\\\\testserver", "", \%lock))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
for $key (sort keys %lock)
{
print "$key = $lock{$key}\n";
}
if(!Win32::Lanman::QueryServiceConfig("\\\\testserver", '', 'myservice', \%config))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
for $key (sort keys %config)
{
if($key eq "dependencies")
{
$dependencies = $config{$key};
print "\t$key = ", $#$dependencies + 1, "\n";
foreach $dependency (@$dependencies)
{
print "\t\t$dependency\n";
}
}
else
{
print "\t$key = $config{$key}\n";
}
}
if(!Win32::Lanman::QueryServiceStatus("\\\\testserver", "", 'myservice', \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
for $key (sort keys %status) { print ``$key = $status{$key}\n''; }
$securityinformation = &OWNER_SECURITY_INFORMATION | &GROUP_SECURITY_INFORMATION
| &DACL_SECURITY_INFORMATION | &SACL_SECURITY_INFORMATION;
if(!Win32::Lanman::QueryServiceObjectSecurity("\\\\testserver", "",
'myservice', $securityinformation, \$securitydescriptor))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
#Do not print these binary data. #print $securitydescriptor;
#build a valid security descriptor #$securitydescriptor = ...
if(!Win32::Lanman::SetServiceObjectSecurity("\\\\testserver", "", 'myservice', &DACL_SECURITY_INFORMATION,
$securitydescriptor))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::QueryServiceConfig2("\\\\testserver", "", 'testserv', \%config))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %config)
{
print "$key = $config{$key}\n";
}
$config{description} = 'This is a service description';
$config{command} = 'c:\\winnt\\system32\\notepad.exe';
$config{rebootmsg} = 'This is a reboot message';
$config{resetperiod} = 100;
#@actions = ({type => &SC_ACTION_NONE, delay => 1000},
# {type => &SC_ACTION_REBOOT, delay => 2000},
# {type => &SC_ACTION_RESTART, delay => 3000},
# {type => &SC_ACTION_RUN_COMMAND, delay => 4000});
#$config{actions} = \@actions;
if(!Win32::Lanman::ChangeServiceConfig2("\\\\testserver", "", 'testserv', \%config))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::QueryServiceStatusEx("\\\\testserver", "", 'testserv', \%status))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %status)
{
print "\t$key = $status{$key}\n";
}
if(!Win32::Lanman::EnumServicesStatusEx("\\\\testserver", "", &SERVICE_WIN32 | &SERVICE_DRIVER,
&SERVICE_STATE_ALL, \%services, 'testgroup'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $service (@services)
{
foreach $key (sort keys %$service)
{
print "\t$key = ${$service}{$key}\n";
}
}
Throughout this section $source will represent the event log source, which can only be ``application'' or ``system'' or ``security''.
To get all events set $first to 1 and $last to -1 (or 0xffffffff if you prefer).
if(!Win32::Lanman::ReadEventLog("testserver", 'system', 0, 0xffffffff, \@events))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Reads all events from the security event log in reverse order on server \\testserver.
if(!Win32::Lanman::ReadEventLog("\\\\testserver", 'security', 0xffffffff, 0, \@events))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Retrieves the first and the last record number in the application log on server \\testserver. Then it reads all these events and prints out the event properties.
if(!Win32::Lanman::GetOldestEventLogRecord("testserver", 'application', \$first))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::GetNumberOfEventLogRecords("testserver", 'application', \$last))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
$last += $first - 1;
if(!Win32::Lanman::ReadEventLog("testserver", 'application', $first, $last, \@events))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $event(@events)
{
#get the event description for the event
${$event}{'eventdescription'} = "*** Error get event description ***"
if !Win32::Lanman::GetEventDescription("\\\\testserver", $event);
${$event}{'eventdescription'} = join('', split(/\r/, ${$event}{'eventdescription'}));
${$event}{'eventdescription'} = join('', split(/\n/, ${$event}{'eventdescription'}));
print '#' x 80;
@keys = sort keys %$event;
foreach $key(@keys)
{
if($key eq 'strings')
{
$strings = ${$event}{$key};
print "strings\n";
foreach $string(@$strings)
{
print "\t$string\n";
}
}
elsif($key eq 'eventid')
{
#this is the event id you'll see in event viewer; the highest 16 bit are discarded
print "$key=" . (${$event}{$key} & 0xffff) . "\n";
#this is the real event id
#print "$key=" . (${$event}{$key}) . "\n";
}
elsif($key eq 'timegenerated' || $key eq 'timewritten')
{
print "$key=" . localtime(${$event}{$key}) . "\n";
}
elsif($key eq 'usersid' || $key eq 'data')
{
print "$key=" . unpack("H" . 2 * length(${$event}{$key}), ${$event}{$key}) . "\n";
}
else
{
print "$key=${$event}{$key}\n";
}
}
}
if(!Win32::Lanman::ReadEventLog("\\\\testserver", 'system', 0, -1, \@events))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $event(@events)
{
#get the event description for the event
${$event}{'eventdescription'} = "*** Error get event description ***"
if !Win32::Lanman::GetEventDescription("\\\\testserver", $event);
print ${$event}{'eventdescription'};
}
if(!Win32::Lanman::BackupEventLog("\\\\testserver", 'application', 'application.evt'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::ClearEventLog("\\\\testserver", 'application', 'application.evt'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Clears the system eventlog on server \\testserver without backing up the events.
if(!Win32::Lanman::ClearEventLog("\\\\testserver", 'system'))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
#build administrators sid
$sid = pack("C16", 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2, 0 , 0);
unless(Win32::Lanman::ReportEvent("\\\\testserver", 'Print', &EVENTLOG_ERROR_TYPE, 100, 256, $sid,
['string1', 'string2', 'string3'], 'Here is my data ...')
) {
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::GetNumberOfEventLogRecords("\\\\testserver", 'system', \$numrecords))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$numrecords\n";
if(!Win32::Lanman::GetOldestEventLogRecord("\\\\testserver", 'system', \$oldestrecord))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print "$oldestrecord\n";
GetLastError() returns 126 (ERROR_MOD_NOT_FOUND).
Wtsapi32.dll needs three additional dlls: utildll.dll, regapi.dll and winsta.dll. Copy
each of these dlls into your system32 directory.
=item WTSEnumerateServers($domain, \@sessions)
Enumerates all WTS server in domain.
This call is not really necessary and only implemented for completeness and for those keenly interested in performance. With the WTS api you have to open a server handle, then call your WTS function and close the handle with WTSCloseServer at the end. The module opens the handle every time you call a WTS function, makes the job and closes the handle at the end. The advantage: you don't need to deal with handles, the downside: the overhead in opening and closing a handle at each call.
WTSCloseServer($handle)WTSInfoClassAll() as @infoclass parameter.
WTSUserConfigAll() as @infoclass parameter.
if(!Win32::Lanman::WTSEnumerateServers("testdomain", \@servers))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $server(@servers)
{
print "${$server}{name}\n";
}
if(!Win32::Lanman::WTSOpenServer("\\\\testserver", \$handle))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
# use the handle # ...
if(!Win32::Lanman::WTSCloseServer($handle))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
WTSCloseServer($handle)
if(!Win32::Lanman::WTSOpenServer("\\\\testserver", \$handle))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
# use the handle # ...
if(!Win32::Lanman::WTSCloseServer($handle))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WTSEnumerateSessions("\\\\testserver", \@sessions))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $session (@sessions)
{
foreach $key (keys %$session)
{
print "$key=${$session}{$key}\n";
}
}
if(!Win32::Lanman::WTSEnumerateProcesses("\\\\testserver", \@processes))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $process (@processes)
{
foreach $key (keys %$process)
{
if($key eq "sid")
{
print "$key=", unpack("H" . 2 * length(${$process}{$key}), ${$process}{$key}), "\n";
}
else
{
print "$key=${$process}{$key}\n";
}
}
}
if(!Win32::Lanman::WTSEnumerateSessions("\\\\testserver", \@sessions))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WTSEnumerateProcesses("\\\\testserver", \@processes))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $session (@sessions)
{
next
if ${$session}{winstationname} ne "";
foreach $process (@processes)
{
next
unless ${$process}{sessionid} == ${$session}{id};
print "${$process}{name} (${$process}{processid}) will be terminated\n";
if(!Win32::Lanman::WTSTerminateProcess("\\\\testserver", ${$process}{processid}, 3))
{
print "Oops, cannot terminate process ${$process}{processid}; error: ";
# get the error code
print Win32::Lanman::GetLastError();
print "\n";
}
}
}
if(!Win32::Lanman::WTSQuerySessionInformation("\\\\testserver", 0, [WTSInfoClassAll()], \%info))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %info)
{
print "$key=$info{$key}\n";
}
if(!Win32::Lanman::WTSQueryUserConfig("\\\\testserver", "testuser", [WTSUserConfigAll()], \%user))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
foreach $key (sort keys %user)
{
print "$key=$user{$key}\n";
}
$user{terminalserverprofilepath} = "\\\\testserver\\testpath\\profile";
$user{workingdirectory} = "c:\\work\\testuser";
if(!Win32::Lanman::WTSSetUserConfig("\\\\testserver", "testuser", \%user))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WTSSendMessage("\\\\testserver", 0, "a message to the console", "hi console user",
0, 15, \$response))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
print $response;
if(!Win32::Lanman::WTSDisconnectSession("\\\\testserver", 0, 1))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WTSDisconnectSession("\\\\testserver", 0, 1))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
if(!Win32::Lanman::WTSWaitSystemEvent("\\\\testserver", &WTS_EVENT_LOGON | &WTS_EVENT_LOGOFF, \$event))
{
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
exit 1;
}
Jens Helberg <jens.helberg@de.bosch.com>
You can use this module under GNU public licence.