PerceivedType – Preview Pane in Windows7

No Comments »

I really like the preview pane of win7, it give you a “good size” outlook of what the file you are looking at is about. I definitely updated my system for with the PDF preview handler from

http://timheuer.com/blog/archive/2008/05/09/foxit-pdf-preview-handler.aspx

How about if I could see my script in the preview pane too?? is that a silly idea?? NOOOO!!

Check this out:

http://msdn.microsoft.com/en-us/library/cc144150%28VS.85%29.aspx

All you have to do is add a registry String value under the extension you want (e.g. HKEY_CLASSES_ROOT\.vbs )

Done!

Posted on August 13th 2010 in IT/ Network Admin

vbScript to Obtain IP Address

No Comments »

Being an administrator, you can’t do much if you don’t know about IP Addresses, and how frustrating and stupid it is that it is so difficult to get the IP Address of a machine is a single variable when you are scripting on Windows!!!

sure you can get it with “IPCONFIG” or “ipconfig | find “IP Address”" (winXP) or ipconfig | find “IPv4″ but that gives you a full line and you have to go filter for the ip address only.

Other solutions, vbscript , method, wmi? or registry?

can do both except that the WMI is weird and doesn’t seem to work similarly on winXP as on win7.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
 
For Each objItem In colItems
wscript.echo objItem.IPAddress(0)
Next

Gives you the address but an error which doesn’t quite seem to make sense..

the other option, get it from Registry. This is tricky because the network interface subkey is different for every machine. The trick is to recursively search the subkey for the ValueName you are looking for.. et voilà!!

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
    strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces"
retval = objReg.EnumKey(HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys)
'WScript.Echo retval
strValueName = "IPAddress"
For Each subkey In arrSubKeys
      strKeyPath1 = strKeyPath & "\" & subkey
	  'wscript.echo strKeyPath
	  Return = objReg.GetMultiStringValue(HKEY_LOCAL_MACHINE,strKeyPath1, _
    strValueName,arrValues)
If (Return = 0) And (Err.Number = 0) Then
' Treat the multistring value as a collection of strings separated by spaces and output
    For Each strValue In arrValues
    WScript.Echo  strValue
Next
End If
 
Next
Posted on August 13th 2010 in IT/ Network Admin

Quick DHCP Server Configuration

No Comments »

I’ve some job coming up where I’ll have to reconfigure a few DHCP servers. GUI interface is great but when you have a lot to do and you don’t want to miss anything, it’s better to have a script ready and check for all configs required. Microsoft somehow got that and moving on with a “core” version for in its 2008 server. Time to really make use of the new “black and white – non-graphical” technology!!

netsh dhcp server <serverip> add scope <scopeip> <scopesubnet> “<ScopeName>” “<Scopedescription>”      
netsh dhcp server <serverip> Scope <scopeip> add iprange <start ip> <last ip>      
netsh dhcp server <serverip> Scope <scopeip> add excluderange <startexcludeip> <last exclude ip>      
netsh dhcp server <serverip> Scope <scopeip> set optionvalue 003 IPADDRESS “<router IP>”      
netsh dhcp server <serverip> Scope <scopeip> set optionvalue 006 IPADDRESS “<DnsSvr1>” “<DnsSvr2>”    
netsh dhcp server <serverip> Scope <scopeip> set optionvalue 015 string  “Domain Name”      
Netsh dhcp server <serverip> Scope <scopeip> set optionvalue 051 DWORD 86400      
netsh dhcp server <serverip> Scope <scopeip> set state 1        
netsh dhcp server <serverip> Scope <scopeip> add reservedip <reserve ip> <mac-address> “<reservename>” “<reserveDescription>” “BOTH”
netsh dhcp server <serverip> Scope <scopeip> add reservedip <reserve ip> <mac-address> “<reservename>” “<reserveDescription>” “BOTH”
netsh dhcp server <serverip> Scope <scopeip> add reservedip <reserve ip> <mac-address> “<reservename>” “<reserveDescription>” “BOTH”
netsh dhcp server <serverip> Scope <scopeip> add reservedip <reserve ip> <mac-address> “<reservename>” “<reserveDescription>” “BOTH”
                   
  1. Copy paste in spreadsheet, update all <..> as required.
  2. Copy paste to a text file,
    1. save as a .BAT, execute wherever with proper permissions.
    2. save to a single file and run using the C:\>netsh exec filename.txt command from the command line.

NB: Option value: 3=ROUTER ; 6=DNS ;15=Lease time; 51=Domain Name;

Posted on June 25th 2010 in IT/ Network Admin

Create or Delete Windows service

No Comments »

1. Run Regedit or Regedt32

2. Find the registry entry

“HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services”

3. Look for the service there and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).

alternatively, you can also use command prompt and delete a service using following command:

sc delete < SERVICE name>

or to create, simply type

sc create <SERVICE name>

Posted on November 2nd 2009 in IT/ Network Admin

Sharepoint Backup & Restore

No Comments »

can be such a b**ch.. but it works pretty well one’s going. We had our new design template this week and I don’t know what happened since then but the servers (server farm of 3 went totally crazy. RPC failure, CPU IERR, disk prediction failure.. that was no good sign to say the least..

The servers were quite old and it took several years to get people interested into using Sharepoint and I just joined the organisation last year. It has plenty of error logs which couldn’t be explained by the consultant who took over the previous consultants few years ago..

I am no Sharepoint expert but really happy I took the Sharepoint Administration training course last year and tried the backup & restore in a test environment. Since we were thinking of changing the servers anyways, and we just set up a couple of thousand bucks in VMware (servers were to go P2V) I decided to install very from scratch and restore the last good backup.It took me a couple of hours to get this working again even if, for some reasons the restore wouldn’t work for the 2-3 initial times. That was weird, the first windows installation wasn’t done by me but it should have been a very straight forward installation which looked pretty fine.. but after 14hours struggling to make the restore work in different methods, mostly with the initial help of the external consultant, I scrapped everything up again, reinstall windows and follow strictly the steps I used in my initial test lab and it worked like a charm. I still need some help to figure out the special customizations that was made before I got there but it’s 99% up and running.

All that to say that my little Notepad file of 2.6 KB saved the day. I wouldn’t say a few Gigs of data ’cause the daily backups were running fine (that’s a 300Bytes batch file ),  but definitely all the effort put in by the Communications department to launch the new template and get people to work with it as the new academic year starts this week.

Document your stuff buddy!! you never know.. They are very basic but here are my two little life savers..

Daily Full Backup Batch File (run in a scheduled task at midnight or so)

@ECHO OFF
REM ***** Backup Sharepoint ******
c:
cd “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN”
set _day=%DATE:~0,3%
net use S: \\RemoteFileBackupServer\Sharepoint /PERSISTENT:NO
stsadm -o backup -url http://portal -filename S:\%_day%\portail.bak -overwrite > c:\temp\log.txt
Net USE S: /delete

Installation (Restore) procedure

- create service account (Domain User) and make it member of the administrators group of the server
- Join Domain
- login as service account (all installation must be made as this service account )
- Install IIS
- Install dotNet3
- Activate ASP.NET v2.0xx in Web service extensions of IIS Admin Manager
- Install (MSSQL Enterprise) – basically MSSQL Services & Workstation components to connect and view the databases
- Install Sharepoint
- Install SharePoint Language Pack French & Language Pack SP 1 & 2
- Check the Central Admin site and activate the services on the servers in order (if using a farm)
- Create an SSP with an Administration Web application
- Check if the profile import is working and it is pulling the information of all the users of the Domain / Entire Forest
- Create a web application for the Sharepoint users site (don’t create the site as suggested one the Web App is installed. )
- Move over the files from the old server to the new server including,
- web.config – in the web server c:\inetpub\wwwroot\…..\<site>\web.config
- Additional features from the application server c:\program files\common files\microsoft shared\web server extensions\12\TEMPLATE\FEATURES
- Special assembly file if any from c:\windows\assembly\gac_msil\

-Install the feature (execute command from the bin folder**)
stsadm -o installfeature -name <features> -force

**c:\program files\common files\microsoft shared\web server extensions\12\bin>

- Backup/ Restore Content database
stsadm -o restore -url http://portail -filename c:\portal.bak

Other method, apparently better, is to use the SQL back of the web application and just attach it to the newly created web application created on the new server.
- Backup and Restore the MSSQL Database (Should be the one with WSS_Content..)
- Go to Central Administration – Application Management – Content Database – add a Content database with the same name under the correct Web Application URL (top right)
OR use in command lines
stsadm -o addcontentdb -url htt://portail -databasename WSS_ Content_Portail -databaseserver PortalSQLServer

Re-assisgn the database (delete the empty newly created one and activate the restored one)

If you have other 3rd party web parts installed, make sure you know how they are installed and configured.

If you are changing the name of the URL, you might have to be assisted and go through all the customized file (e.g. web.config, 3rd party configuration) and replace the URL used.. (search & replace)

Launch the site, give it some time initially to start the page and it should work fine..

Posted on September 7th 2009 in IT/ Network Admin

SSL at work..

No Comments »

Lengthy but good and necessary reminder of how SSL works by Simon Denis.. :)

Check how Private Key & Public Key works if you don’t already know.. (some more reading.. , or just find another video.. :) )

Now you know that;

1. The Certificate Authority (CA e.g. Verisign, thwate, your own server..) has a a KEY (private) and a Certificate (public key + extra about the Organisation) – these files that will be generated from the codes below as ca.key and ca.crt (certificate)

2. The Server (or webserver) also has a KEY and will get its Server Certificate from the CA. To get this certificate, it will first generate a Certificate Request that will be sent to the CA. Once the CA validates that the requester is genuine, it will sign the Certificate Request with his Certificate and KEY to produce the Server Certificate. In this case we have 3 files to be generated, server.key, server.csr (Certificate Request), server.crt (Server certificate) .
(For windows mortals server.csr = certreq.txt AND  server.crt = server.cer )

Question : I have set up my web server on windows IIS, I need to put in a certificate to enable SSL but this is just a test site and I know want to buy an SSL certificate with Verisign or Thwate or … What should I do ?

Answer : Hmm.. good question me!! well build your own CA, generate your certificates, get the certificate request from the IIS, sign it and put back the resulting server certificate into the webserver. You will get a prompt that the website isn’t signed by a trusted CA but who cares.. I am the untrusted party!!

I prefer making my self signed CA with Linux as it is easily installed and just a 2 lines command. You’ll need openssl and see my previous blog to see how to install it on a windows client if you need to.

Note for the newbies..

1. Both CA and Server will request for information about each Organizations or company, DON’T use the exact same Common Name (CN) for both, use the example below (added “CA” at the end of the CA’s CN):

Creating Certificate Authorities and self-signed SSL certificatesCA:
Common Name (CN): www.mysite.com CA
Organization (O): mysite
Organizational Unit (OU): none

Server:
Common Name (CN): www.mysite.com
Organization (O): mysite
Organizational Unit (OU): none

————————————    LINUX  ————————————

Once you get to the command line with openssl:

Generate CA Key : Creating Certificate Authorities and self-signed SSL certificates
$ openssl genrsa -des3 -out ca.key 4096

Generate CA Certificate :
$ openssl req -new -x509 -days 365 -key ca.key -out ca.crt
Get Server Certificate (generate the key by the same way..)
—————————————————————————————
————————————    Microsoft ————————————
1. Open IIS Manager (using version 6.), unfold the trees and right click on the website requiring encryption and click properties
2. Go to Directory Security, Click Server Certificate.
3. Next, Create new certificate,  Prepare the request but send it later,  – Next .. put the details (use your website FQDN as the DN, use the same key length as you used on your server )  next.. next..
4. Save the Server Certificate Request (certreq.txt) and you’ll need to transfer that to the linux box. (Don’t scratch your head.. that’s easy, if you used Cygwin on windows, just copy-paste the file in c:\cygwin\tmp or use a usb or network share linux does that too :p )
————————————————————————————
————————————    LINUX  ————————————
Sign and Validate Server Certificate on CA
$ openssl x509 -req -days 365 -in /tmp/certreq.txt -CA ca.crt -CAkey ca.key -CAcreateserial -out server.cer
*note /tmp/certreq.txt is if you copied the file to in c:\cygwin\tmp
copy back the Server Certificate to the IIS Server
$ cp server.cer /tmp/ -if using cygwin
—————————————————————————————-
————————————    Microsoft  ————————————
Go to Directory Security again, and Click Server Certificate
click Process the pending request and install the certificate
Browse to get the server.cer, next use port 443 (meant for https) , next ..
————————————-  FINISH!! ————————————-
There.. you’re done.. now your website is https with a self signed Certificate.
Posted on August 22nd 2009 in IT/ Network Admin

Installing Cygwin (linux) and OpenSSH on Windows VISTA/ 7

No Comments »
Cygwin
OpenSSH

1. Make sure you have a local user that has access to the machine

2. OpenSSH is bundled available in an application called Cygwin. Cypwin is actually a emulation of linux shell that you install on Windows. Download the setup.exe Cygwin from the project homepage.

3. Double click and launch setup.

4. Leave the default choice as Install from Internet and click Next.

5. Change the directory to C:\cygwin if it is not already populated and leave the default selections as All Users and Unix/binary and click Next.

6. On the Select Local Package Directory Prompt. Change the directory to C:\Cygwin if it is not already populated and click Next.

7. Leave your Internet connection as Direction Connection and click Next.

8. Choose any mirror and click Next. (I used the waterloo in CA..)

9. Make sure you install the OpenSSH package !! – Unfold the Net tab and then double-click on OpenSSH.

It will take a few minutes for Cygwin to install your necessary packages depending on the speed of your Internet connection and the mirror you chose.

10. Leave Create icon on Desktop and Add icon to Start Menu checked and click Finish.

Installation of Cygwin should complete without error. If windows is giving you a hard time, don’t give up, just start over.. eventually it’ll get it and Cygwin does install.

At any point when you do the following, it might tell you that such and such files/folders permissions are not accessible or writable etc.. Just chown the folders as it asks and change them afterward back to what they were..

11. Right-click the icon on your Cygwin icon on your desktop and chose Run as Administrator.

12. To configure your SSH Server (Open SSH) type ssh-host-config.

13. Cygwin will then ask “Should privilege separation be used?” Answer Yes.

14. Cygwin will then ask “Should this script create a local user ‘sshd’ on this machine?” Answer Yes.

15 Cygwin will then ask “Do you want to install sshd as service?” Answer Yes.

16. Cygwin will then ask “Should this script create a new local account ‘ssh_server’ which has the required privileges?” Answer No.

17. Cygwin will then ask “Which value should the environment variable CYGWIN have when sshd starts?” Answer ntsec tty.

18. Acknowledge all Infos and warnings.. and there.. SSH Server is complete.

19. Start your SSH Server by typing net start sshd and hit Enter

20. launch your ssh client from a remote station (e.g. putty) and ssh to your machine using your windows local username & password.

Posted on August 22nd 2009 in IT/ Network Admin

Windows time synchronization

No Comments »

How to synchronize the time on a member computer in an Active Directory domain

Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
Type w32tm /resync, and then press ENTER.
How to synchronize an internal time server with an external source

Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
Type the following line, where peerlist is a space-separated list of Domain Name System (DNS) names or IP addresses of the appropriate time sources, and then press ENTER:
w32tm /config /syncfromflags:manual /manualpeerlist:peerlist
Type w32tm /config /update, and then press ENTER
Reference : http://support.microsoft.com/kb/307897

Posted on July 17th 2009 in IT/ Network Admin

Enable Remote Desktop Remotely

No Comments »

You can also enable remote desktop over the network via regedit if you have administrator rights to the remote machine:

1. Run Regedit
2. Select File –> Connect Network registry
3. Enter the name of the remote computer and select Check Name

At the bottom of the registry tree you will see 2 Hives appear Hkey_Local_Machine and
Hkey_Users (under the remote computer’s name)

4. Goto hklm\system\currentcontrolset\control\terminal server\FdenyTSConnections=1
5. Change the FdenyTSConnections to 0
6. Attempt to Re-Login

To enable remote access to a machine via the command line, type:
psexec \\remotecomputername netsh firewall set service remoteadmin enable
psexec \\remotecomputername netsh firewall set service remotedesktop enable

Posted on July 17th 2009 in IT/ Network Admin

Checking disk space and service > Excel file

No Comments »

Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

objExcel.Cells(1, 1).Value = “Machine Name”
objExcel.Cells(1, 2).Value = “Drive”
objExcel.Cells(1, 3).Value = “Total Size”
objExcel.Cells(1, 4).Value = “Free Space”
objExcel.Cells(1, 5).Value = “Free Space Percentage”
objExcel.Cells(1, 6).Value = “SNMP Service status”

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile(“F:\Script\MachineList.txt”, 1)

Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
Set objWMIService = GetObject(“winmgmts://” & strComputer & “”)

Set colDisks = objWMIService.ExecQuery (“SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3″)

For Each objDisk In colDisks
objExcel.Cells(intRow, 1).Value = Ucase(strComputer)
objExcel.Cells(intRow, 2).Value = objDisk.DeviceID
objExcel.Cells(intRow, 3).Value = FormatNumber(objDisk.Size/1024, 0)
objExcel.Cells(intRow, 4).Value = FormatNumber(objDisk.FreeSpace/1024, 0)
objExcel.Cells(intRow, 5).Value = FormatPercent(objDisk.FreeSpace/objDisk.Size, 0)

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2″)
Set colServices = objWMIService.ExecQuery (“Select * from Win32_Service Where Name = ‘snmp’”)

For Each objService in colServices
if objService.State =”Stopped” Then
objService.StartService()
objExcel.Cells(intRow, 6).Value = objService.DisplayName & ” has been restarted”
Else
objExcel.Cells(intRow, 6).Value = objService.DisplayName & ” ” & objService.State
End If
Next

intRow = intRow + 1

Next
Loop

objExcel.Range(“A1:F1″).Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Wscript.Echo “Done”

Posted on July 17th 2009 in IT/ Network Admin