Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The Samba server of my company doesn't provide a reliable way to introduce the logon scipts for the different offices.

Now my question is: How can I deposit the script so that the computer maps the drives excactly for the different users in different offices.

For each office I already have an extra .bat file with their special network drives. But how could the computer know, which person is logging on? I mean in which department of the company does the user work and somehow which .bat file do we need?

share|improve this question

1 Answer 1

Use local group policy.

logon script path:

%windir%\system32\GroupPolicy\User\Scripts\Logon\

logoff script path:

%windir%\system32\GroupPolicy\User\Scripts\Logoff\

Startup script path:

%windir%\system32\GroupPolicy\Machine\Scripts\Startup\

Shutdown script path:

%windir%\system32\GroupPolicy\Machine\Scripts\Shutdown\

Add logon registry key:

regedit /s \\PDC-Kerberos-Server-Samba\profiles\logon.reg

logon.reg:

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon]

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0]
"GPO-ID"="LocalGPO"
"SOM-ID"="Local"
"FileSysPath"="C:\\WINDOWS\\System32\\GroupPolicy\\User"
"DisplayName"="Local Group Policy"
"GPOName"="Local Group Policy"

[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logon\0\0]
"Script"="logon.bat"
"Parameters"=""
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

Logon script GPO, GUI way:

logon script GPO

Best way: LabTracker

  1. Create a common scenario that will determine the user's name and the environment variables including - department, if it is brought to the LDAP Server or Active Directory.

  2. After that, in this scenario on the basis of the data call other scripts. Below are examples of determining the user's surroundings. On these data, you can build the conditions necessary for you to run scripts.

  3. Calling script form the user's environment.

The best option, in my opinion WSH (vbscript) but you can also use commands only.

If you need a cross-platform, the python, perl and java quite well on all operating systems.

real query user DN:

 dsquery *  -filter "(samAccountName=Tcheburator)" -attr distinguishedName | more +1

Output, (OU - Orgainazation Unit):

 CN=Tcheburator,OU=In App,OU=View App,DC=ht,DC=local

query in script user DN:

 dsquery *  -filter "(samAccountName=%username%)" -attr distinguishedName | more +1

query in script user group:

 dsquery user -samid %username% | dsget user -memberof | dsget group -sid -samid

query in script user Nesting groups:

 dsquery user -samid %username% | dsget user -memberof -expand | dsget group -sid -samid

real sample, query user group:

dsquery user -samid Tcheburator | dsget user -memberof | dsget group -sid -samid

Output:

  samid           sid
  Nected Tche     S-1-5-21-2191659736-2261162383-3034376108-1153
  Tche            S-1-5-21-2191659736-2261162383-3034376108-1152
  Domain Users    S-1-5-21-2191659736-2261162383-3034376108-513
dsget succeeded

real sample, query user Nesting groups:

dsquery user -samid Tcheburator | dsget user -memberof -expand | dsget group -sid -samid

Output:

  samid           sid
  Nected Tche     S-1-5-21-2191659736-2261162383-3034376108-1153
  Tche            S-1-5-21-2191659736-2261162383-3034376108-1152
  Domain Users    S-1-5-21-2191659736-2261162383-3034376108-513
  DHCP Administrators    S-1-5-21-2191659736-2261162383-3034376108-1129
dsget succeeded

query department:

dsquery * -filter "(samAccountName=Tcheburator)" -attr name objectSid msNPAllowDialin adminCount whenChanged  whenCreated department l telephoneNumber

Output:

  name           objectSid                                         msNPAllowDialin    adminCount    whenChanged            whenCreated            department    l             telephoneNumber
Tcheburator    S-1-5-21-2191659736-2261162383-3034376108-1151                                     06/12/2013 14:53:08    06/12/2013 10:18:36    View IT       New Vasyki    (322) 223-322

query all:

dsquery * -filter "(samAccountName=Tcheburator)" -attr *

get OS, service pack, computer name:

wmic OS get Caption, Version, BuildNumber, CSDVersion, CodeSet, CSName, LocalDateTime

Output:

BuildNumber  Caption                                                     CodeSet  CSDVersion      CSName         LocalDateTime              Version
3790         Microsoft(R) Windows(R) Server 2003 Enterprise x64 Edition  1251     Service Pack 2  W2K3R2VIRT-2ECA  20130612191856.656000+240  5.2.3790

get OS, service pack, computer name ... install date, system disk:

wmic os get BootDevice,BuildNumber,CSDVersion,Version,CSName,InstallDate,LastBootUpTime,OSLanguage,Locale,SystemDevice,SystemDirectory,SystemDrive

get IP address, MAC Address, GW ...:

wmic nicconfig get MACAddress, IPAddress, IPSubnet, DefaultIPGateway, Index, ServiceName, Description, SettingID

Output:

DefaultIPGateway  Description                                             Index  IPAddress          IPSubnet           MACAddress         ServiceName   SettingID                               
                  RAS Async Adapter                                       1                                                               AsyncMac      {06CDF9C4-7DFE-4CF0-8DF4-08D86275188F}  
                  WAN Miniport (L2TP)                                     2                                                               Rasl2tp       {2F53E6CE-FE90-41FF-9346-7FE854731431}  
                  WAN Miniport (PPTP)                                     3                                            50:50:54:50:30:30  PptpMiniport  {FA6F7372-8CCB-4DAC-9B74-51501B322F83}  
                  WAN Miniport (PPPOE)                                    4                                            33:50:6F:45:30:30  RasPppoe      {075EB914-2B27-42AA-8176-7A58987C7FA9}  
                  Direct Parallel                                         5                                                               Raspti        {F992BAE1-1E06-4069-A8AE-6FFA487BC9CC}  
                  WAN Miniport (IP)                                       6                                                               NdisWan       {61EC9DB7-4374-4917-B7DA-A9182B6332DE}  
{"10.120.10.1"}   Atheros AR8121/AR8113/AR8114 PCI-E Ethernet Controller  7      {"10.120.10.100"} {"255.255.240.0"}   6В:77:C7:7A:79:BB  L1e           {4EB8AC6D-15EE-4922-94F6-3FB0CED90635}  
                  Broadcom 802.11g Network Adapter                        8                                                               BCM43XX       {A245F36E-6EAA-4880-9CE1-A536C2F2A000}  
                  Packet Scheduler Miniport                               9                                            34:B3:20:52:41:53                {CE21D017-A6B3-4275-9BC5-3060B4F017A0}  
                  VMware Virtual Ethernet Adapter for VMnet1              10     {"192.168.18.1"}   {"255.255.255.0"}  00:50:56:C0:00:01  VMnetAdapter  {EB270DB9-E2B1-4689-86BF-4CBC4E30A93B}  
                  VMware Virtual Ethernet Adapter for VMnet8              11     {"192.168.232.1"}  {"255.255.255.0"}  00:50:56:C0:00:08  VMnetAdapter  {90EDFB26-FF76-4FF8-8E25-A847F7179F34}  
                  Packet Scheduler Miniport                               12                                                                            {A95F18B8-8423-4DDF-84C0-240BEF25B647}  
                  1394 Net Adapter                                        13                                                              NIC1394       {9C5F9D9E-9BA5-4C2F-AB8C-6A7EDC7A1C78}  
                  TAP-Win32 Adapter V9                                    14                                                              tap0901       {63D6E2AA-FDC6-41A4-B3CD-B3460D63A5E8}  
                  Packet Scheduler Miniport                               15                                                                            {7F4D8138-D586-4511-B737-7E05168430AB}  
                  Windows Mobile-based Internet Sharing Device            16                                                              usb_rndisx    {3E7051D2-8097-4986-8EE3-E88F028C9E07}  
                  Packet Scheduler Miniport                               17                                                                            {3909CC6A-B904-4BEA-9CEE-E6801BFF4694}  
                  Windows Mobile-based Internet Sharing Device            18                                                              usb_rndisx    {284F5467-6DE8-4398-9881-C22AEB44A0B7}  
                  Packet Scheduler Miniport                               19                                                                            {27EED4EC-0B03-4D39-B120-45C24E8BB0CE}  
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.