Search This Blog

Thursday, July 04, 2013

Configure a bunch of HP Thin Clients with fixed IPs

@echo off
:: A script to assign incremental fix ips to Thin Clients
:: Needs psexec (http://live.sysinternals.com/psexec.exe) in order to run with administrative rights
:: 2013/07/04 neXt (s@xxxxxxxx.com) Initial release

:: set variables
setlocal
set user=Administrator
set pass=Administrator
set iprange=192.168.3
set nmask=255.255.255.0
set gateway=192.168.3.254
set dns1=192.168.3.3
set dns2=192.168.1.3
set startip=200

:: we need a common location to save the last used IP.
set "conf=ips.txt"
IF not EXIST %conf% (
echo DEBUG: Config file does not exist! Creating %conf% with the starting IP %iprange%.%startip%
(echo %startip%)>"%conf%"
)

:: get the saved IP and increment it by 1
for /f "usebackq delims=." %%N in ("%conf%") do set /a newip=%%N+1
if %newip% GTR 254 (
echo IP can not be bigger than 254! Please Check the IP Range!
pause
exit /B


:: put back the new IP 
(echo %newip%)>"%conf%"

:: in order to change the IP, we need to identify the local network adapter name
For /f "skip=2 tokens=4*" %%a In ('NetSh Interface IPv4 Show Interfaces') Do (

Call :UseNetworkAdapter %%a "%%b"
)

Goto :End

:UseNetworkAdapter
:: varibles: %1 = State; %2 = Name (quoted); %~2 = Name (unquoted)
If %1==connected (

:: Ignore Loopback interface
echo.%2|findstr /C:"Loop" >nul 2>&1
if errorlevel 1 (

echo DEBUG: Interface: %2 IP: %iprange%.%newip% Mask: %nmask% GW: %gateway% DNS: %dns1% %dns2%
psexec -u %user% -p %pass% netsh interface ip set address name=%2 static %iprange%.%newip% %nmask% %gateway% 1
psexec -u %user% -p %pass% netsh interface ip set dns name=%2 static %dns1%
psexec -u %user% -p %pass% netsh interface ip add dns name=%2 %dns2% index=2

:: save the thin client state and reboot
psexec -u %user% -p %pass% ewfmgr c: -commit
psexec -u %user% -p %pass% shutdown -r -f -t 2
))

:End
endlocal

Saturday, February 02, 2013

Move Local Computer to a different OU

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set WshNetwork = WScript.CreateObject("WScript.Network")
set objOU = GetObject(LDAP://ou=localComputers,ou=SOME_OU,dc=domain,dc=local)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _"SELECT ADsPath FROM 'LDAP://dc=domain,dc=local' WHERE objectCategory='computer' " & _"AND Name='" & wshNetwork.ComputerName & "'"

'Wscript.Echo " " & wshNetwork.ComputerName
Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strADsPath = objRecordSet.Fields("ADsPath").Value objOU.MoveHere strADsPath, vbNullString
objRecordSet.MoveNext
Loop

Wednesday, January 02, 2013

Tehnium 08-09/1995 (lang:RO)

Yes, there was a time when I was doing everything analog. Then it came a time when even my audio amplifiers where "Class D" and I designed way smarter digital security systems based on real microcontrollers (among many other things), but I will always remember with pleasure my first successful (as in "I sold more than 10" :) ) product:

Friday, December 07, 2012

Add all Domain Users to Local Administrators (French or English)

Option Explicit
Dim owShell, oWMI, colOperatingSystems, oOS, strComputer, strUser, strDomain, objLocalAdminGroup, sComputer, iOSLang, strAdmins  
On Error Resume Next
Set oWShell = CreateObject("Wscript.Shell")
strComputer = oWShell.ExpandEnvironmentStrings("%computername%")
strDomain = oWShell.ExpandEnvironmentStrings("%userdomain%")
'strUser = strDomain & "\" & oWShell.ExpandEnvironmentStrings("%username%")
strUser = strDomain & "\Domain Users"
Set oWMI = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer _
    & "\root\cimv2")
Set colOperatingSystems = oWMI.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each oOS in colOperatingSystems
  iOSLang = oOS.OSLanguage
Next
If iOSLang = "1033" Then
strAdmins = "/Administrators"
Else
strAdmins = "/Administrateurs"
End if
Set objLocalAdminGroup = GetObject("WinNT://" & strComputer & strAdmins)
objLocalAdminGroup.Add("WinNT://" & Chr(34) & strUser & Chr(34))
Set objLocalAdminGroup = Nothing

Saturday, November 17, 2012

BES - enable http auth

Because the BlackBerry browser uses the BES server to render the pages, the default user for integrated authentication is always "besadmin"
In order to allow the user to authentify itself, we must enable Authentication support on the MDS. Follow KB15642 on bb site  or just

 For BlackBerry Enterprise Server 4.1:
         1. In BlackBerry Manager, select <BlackBerry_Enterprise_Server_name>_MDS-CS_1.
         2. Click Edit Properties. 
         3. In the Properties window, click HTTP.
         4. Under Authentication set the Support HTTP Authentication to True.


  For BlackBerry Enterprise Server 5.0
         1. Open the BlackBerry Administration Service.
         2. Expand the BlackBerry Solution topology.
         3. Expand the component view.
         4. Select MDS connection service.
         5. Select the http tab.
         6. Set authentication support enabled to yes.
         7. If you change this configuration, you will need to restart the BlackBerry MDS service in the Windows Services window.

Configure the MDSLogin.conf file to include your domain name. This will populate the domain field for the BlackBerry smartphone user when they are prompted for credentials on their BlackBerry smartphone. Complete the following steps:

1.On the BlackBerry Enterprise Server, go to C:\Program Files\Research In Motion\BlackBerry Enterprise Server\MDS\Servers\servername\config. 
2.Open the MDSLogin.conf file in a text editor. 
3.Edit the MDS_Default section by replacing COMPANY.COM with your domain name.

Note: If the domain name starts with a number, surround the domain name with quotes ("")

4.If you wish to force a particular authentication type you can change the relevant optional entry to required. 
 
 Save and close the file.
 
C. Configure the krb5.conf file to include details relevant to your specific Microsoft Active Directory environment as follows:
    On the BlackBerry Enterprise Server navigate to C:\Program Files\Research In Motion\BlackBerry Enterprise Server\MDS\Servers\servername\config. 
 

1.Open and edit the krb5.conf in a text editor.

The default sections and entries contained within this file are as follows:
[libdefaults]
default_tkt_enctypes = des-cbc-md5 ; or des-cbc-crc
default_tgs_enctypes = des-cbc-md5 ; or des-cbc-crc
[realms]
# change COMPANY.COM to your Kerberos realm
# change KDC:88 to the hostname:port of KDC
COMPANY.COM = {
kdc = your_kdc.your_domain.com:88} 
2.Replace the COMPANY.COM entry under the [realms] section with your domain name. Ensure this entry is in UPPER case.  
3.Enter the Fully Qualified Domain Name (FQDN) of the KDC within your Microsoft Active Directory environment and port number (if changed from the default of 88). Ensure host names and domain names are in lower case.  
4.Restart the BlackBerry MDS Connection Server service in Windows Services

Wednesday, October 17, 2012

Saturday, October 06, 2012

Remove weird characters from filenames


paste <(find . -print | awk '{print "\042"$0"\042"}') <(find . -print | sed -e 's/\o300/A/g' -e 's/\o301/A/g' -e 's/\o302/A/g' -e 's/\o340/a/g' -e 's/\o341/a/g' -e 's/\o342/a/g' -e 's/\o307/C/g' -e 's/\o347/c/g' -e 's/\o310/E/g' -e 's/\o311/E/g' -e 's/\o312/E/g' -e 's/\o350/e/g' -e 's/\o351/e/g' -e 's/\o352/e/g' -e 's/\o316/I/g' -e 's/\o356/i/g' -e 's/\o322/O/g' -e 's/\o323/O/g' -e 's/\o324/O/g' -e 's/\o362/o/g' -e 's/\o363/o/g' -e 's/\o364/o/g' -e 's/\o331/N/g' -e 's/\o361/n/g' -e 's/\o331/U/g' -e 's/\o332/U/g' -e 's/\o333/U/g' -e 's/\o371/u/g' -e 's/\o372/u/g' -e 's/\o373/u/g' -e 's/\o357/i/g' -e 's/\o317/I/g' -e 's/\o264/_/g' -e 's/\o250/_/g' -e 's/[)(]/-/g' -e 's/^\(.*\)$/"\1"/') | sed -e 's/^/mv /'

pretty neat, heh?
I'm using awk when I define the source because sed -e 's/.*/"&"/' or 's/^\(.*\)$/"\1"/' fails in the weird characters.

 And while being there, find . -type f -regextype posix-extended ! -iregex '.*.(mp3|avi|mkv|wmv|mp4|mp5|flv|M4V|mpeg|mov|m1v|m2v|3gp|avchd)$' -delete will nicely clean up the music folders :)


the characters definitions are found in  /usr/share/X11/locale/iso8859-1/Compose

Monday, September 17, 2012

Clear Win7 UserProfile

' Clear Win7/Win2008 User Profile and registry
' to be executed on each Terminal Server
'(c)2012-2014 sorinakis@gmail

Set WshShell = CreateObject("WScript.Shell")
Set WshNet = WScript.CreateObject("WScript.Network")
Set WMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
set WshFSO = CreateObject("Scripting.FileSystemObject")
const HKEY_LOCAL_MACHINE = &H80000002

dim strUser
Do
strUser = InputBox(vbCrLf & "Please enter the username you wish to reset: ", "Profile Cleaner")

 If TypeName(strUser) = "Empty" Then
     WScript.Quit
 End If
If Len(Trim(strUser)) = 0 Then
     MsgBox "You have to Enter Username To Reset",48
 End If
Loop While Len(Trim(strUser)) = 0
'' debug
'with createobject("wscript.shell")
'.popup "User: " & strUser , 5 , "Info"
'end with
'' end debug
if CStr(CheckUser(strUser)) then
Set Account = WMIService.Get("Win32_UserAccount.Name='" & strUser & "',Domain='" & WshNet.UserDomain & "'")
strRegKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" + Account.SID

if CheckRegKey(strRegKey) then
strUserProfile = WshShell.ExpandEnvironmentStrings(WshShell.RegRead("HKEY_LOCAL_MACHINE\" + strRegKey + "\ProfileImagePath"))
strRmtFldr = WshShell.ExpandEnvironmentStrings(WshShell.RegRead("HKEY_LOCAL_MACHINE\" + strRegKey + "\CentralProfile"))
Else
MsgBox "  The registry key for user " & strUser & " does not exist! Can NOT backup and clean anything!" & vbCrLf & vbCrLf & "Please manually check for and rename the USERPROFILE and ROAMINGPROFILE Folders.",16
wscript.quit
End If
strRegFile = strUserProfile & "\reg_backup.reg"
regCmd = "regedit.exe /E """ & strRegFile & """ " & """HKEY_LOCAL_MACHINE\" & strregKey & """"

If WshFSO.FolderExists (strUserProfile) Then
 '' debug
 'with createobject("wscript.shell")
 '.popup "Backup: " & strUserProfile , 5 , "Info"
 'end with
 '' end debug
WshShell.Run regCmd, 0, True
 WshFSO.MoveFolder strUserProfile , strUserProfile & ".backup"
End If

If WshFSO.FolderExists (strRmtFldr) Then
 '' debug
 'with createobject("wscript.shell")
 '.popup "Backup: " & strRmtFldr , 5 , "Info"
 'end with
 '' end debug
   WshFSO.MoveFolder strRmtFldr , strRmtFldr & ".backup"
End If

 '' debug
 'with createobject("wscript.shell")
 '.popup "Removing: HKEY_LOCAL_MACHINE\" & strRegKey , 5 , "Info"
 'end with
 '' end debug
 DeleteSubkeys HKEY_LOCAL_MACHINE, strRegKey
 Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strRegKey)
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strRegKey, arrSubkeys
    If IsArray(arrSubkeys) Then
        For Each strSubkey In arrSubkeys
            DeleteSubkeys HKEY_LOCAL_MACHINE, strRegKey & "\" & strSubkey
        Next
    End If
    objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strRegKey
 End Sub


' Open the backed up profile it in explorer...

'strPath = "explorer.exe /e, strRmtFldr" & ".backup"
'WshShell.Run strPath 

'debug
  with createobject("wscript.shell")
 .popup "Profile of " & strUser & " has been processed.", 5 , "Info"
 end with
 '' end debug
wscript.quit                  
Else
MsgBox  "USER " & strUser & " NOT FOUND!", 16
wscript.quit
End If

Function CheckRegKey(strRegKey)
On Error Resume next 
strUserProfile = WshShell.ExpandEnvironmentStrings(WshShell.RegRead("HKEY_LOCAL_MACHINE\" + strRegKey + "\ProfileImagePath"))
  If Err.Number <> 0 Then
    Err.Clear
CheckRegKey = false
else
   Err.Clear
CheckRegKey = true
End If
end function

          
Function CheckUser(user)
On Error Resume next
with CreateObject("WScript.Shell")
Set Account = WMIService.Get("Win32_UserAccount.Name='" & User & "',Domain='" & WshNet.UserDomain & "'")
end with
CheckUser = (Err.Number = 0)
On Error Goto 0
end function