Thursday, November 11, 2010

Net stop command does not work in batch file

We have a batch file with essentially below two lines


netsh adv cons add rule name="blahblah" [big blah blah]
net stop ikeext & NET start ikeext


Usually, this should stop the service  ikeext & then start it again, but it failed to stop the dependent services and thus could not restart. Same sequence works perfect on command prompt.

SOLUTION
Add few timeout commands in between and break processing in mulpiple commands. Timeout command is natively available on windows vista onwards.

netsh adv cons add rule name="blahblah" [big blah blah]

TIMEOUT /T 5
net stop ikeext
TIMEOUT /T 15
sc query ikeext   |   findstr   /i   RUNNING   2> NUL   1> NUL
IF  %ERRORLEVEL%   EQU  1  (  NET start "ikeext"  )   else   (  echo "ikeext service already running"  )

Wednesday, November 3, 2010

Single line Commands on Windows

Check if a domain user exists. Add user if it does not exist.
  • Net localgroup Administrators  |  findstr /i UserName1  > NULIF %ERRORLEVEL%  NEQ 0  ( net localgroup Administrators UserName1 /ADD )
Check if a share exists. Create share if it does not exist.
  • Net Share | findstr  /i  %SystemDrive%\Temp  |  findstr /i my > NUL  &  IF %ERRORLEVEL%  NEQ 0  ( net share My=%SystemDrive%\Temp /GRANT:Users,FULL )
Change File permissions inside a folder
  • Applicable vista onwards.
  • DIR C:\Temp\WinTest-*.log 2> NUL 1> NUL & IF %ERRORLEVEL% EQU 0 FOR %I in (C:\Temp\WinTest-*.log) do ICACLS %I /grant EveryOne:(F)

There will definitely be Powershell, WMI and Vbscript way of doing same thing, but sometimes we do need CMD commands.

Wednesday, October 13, 2010

Recent miscellaneous experiences and observations

 

  • Adobe is adding too much junk in our recycle bin folders. It is seriously hampering the work by reducing HDD available size heavily.
  • When seeing downloaded videos like NPTEL from YouTube, it is good to use a wireless headphone. Keep laptop away and turn off wireless service. This way a good video can be finished much quicker than the laptop kept nearby. This becomes possible due to avoidance of constant itching to use internet and neck being in comfortable position.
  • Facebook is so ubiquitous that it is appearing even on restaurant menus. And even on http://licindia.in, an insurance company, homepage. Google must be having real tough time seeing first big loss on online space where they were first movers.
  • When installing new OS, it is better to remove secondary HDD from machine. I am stuck with an IDE drive on machine that cannot be removed since SATA based OS has its boot loader on IDE drive.
  • In India, it is good to open your PC every 2nd month and clean cabinet fan and SMPS fan. SMPS fans are inside the warranty seal, but if it is Rs 400-500 one, then why to bother with warranty. Dirt accumulated on them made PC makes too much noise. Do general brushing on other parts also.
  • Regularly use DVD writer, else they will fail when you really need them.
  • All available indications shows that WP7 will continue to be also-ran, but no market leader in near future.
  • Recent DDR3 & N455 powered netbooks are high on performance, but not on battery power compared to widespread DDR2 N450 powered ones.

Sunday, October 10, 2010

Windows problems with heavily loaded machine

Mixing boot device
I have a 3 HDD machine now, one of which is IDE drive. IDE drive is original drive on machine. Other two are SATA drives. Even though no OS exists on IDE drive as well as both drives in it are formatted, windiws continue to keep critical boot loading files in this hard disk. Removing this results in boot failure. I am still searching for the soultion after banging my head for around 8 hours. Lets see when that solution comes? Some blog post are offering solutions, but need to be in correct bend of mind to pursue them.

Unable to recognize USB ports.
Once I attached 3rd HDD which is SATA, windows stopped recognizing any USB ports except those used for mouse & keyboard. All front and back USB went bad and haywire. FInally, I had to go into BIOS and do "Load default optimized settings" which turned off VT support. This is intel DP8545SG motherboard. But, USB started getting recognized after that. After that, I enabled VT support and things are still fine. Let see how long, since seagate manager still has issue recognizing external HDD when opened. Some delay seems to be there.

Rediffmail login issue

Since friday 9th oct 2010, I was facing issue accessing my rediffmail account. And it happened on 4 places, 2 desktops (one at home, another at office), my personal netbook at home as well as my mobile. Everywhere, rediff told me to try after a while and it went on for 2 days. Then checking some forums clicked an eureka moment. In all of these places, I had enabled "Keep me signed in". So, I signed out from rediff.com page and then signed in again. This resulted in things starting to work again. It seems some cookie was in stale mood and not in sync with server. Whatever, problem is resolved !!!!!!!!

But, rediff could seriously do with some good PMs and testers. Just asking users to tryu after a while when it is cookie expired issues is really bad designing.

Monday, September 13, 2010

Rebooting machine via standard user on Windows

While trying to write an automation, I needed to reboot machine using non-administrator user on server 2003 and windows xp. General way to do the same is to use one of the following ways

InitiateSystemShutdownEx API
Shutdown /r /f

Both of these failed with "Access denied" error. In case of  API, OpenProcessToken returned the error. OpenProcessToken is first step to acquire privilege SE_SHUTDOWN_NAME. Access denied error in this API. Obvious answer is to use impersonation APIs and then  attempt. Still same failure. It seems simple impersonation cannot help acquire required permissions, even in server 2003 & XP.

Next attempt was to check some sysinternal tool to be able to reboot. Mind it, I know all passowrds in plaintext as it is test automation. Even PsShutdown tool had same issue.

Finally, A hacky solution was found and that is add our standard user to "Backup operators" group which can be easily done through the API "NetLocalGroupAddMembers". Problem solved. No security issues either and achieved my shutdown work within same application.

Sunday, May 16, 2010

Issue with Airtel Broadband: Network not getting detected after reboot

 

I had this issue since last 2 months. On rebooting the machine, network address was not getting acquired. Airtel probably made some setting change and my connection got screwed up.  

To get around the issue, I was running below power shell script on reboot every time. Since it needs to be run as administrator, there is no point putting it as login script. A pain for long time. Or manually, I needed to disable and enable network interface to get network address.

NetworkInterfaceSetting.ps1
  1. #==============================================================================
  2. # 3 ways to enable and disable a physical network interface using WMI.
  3. # All boils down to finding device id of a relevant interface
  4. # All gets into a single function as you see, so this function can be
  5. # used in pipeline out of this script also.
  6. # 17 May, 2010
  7. # Tested using Powershell 2.0 on windows 7 x64 ultimate.
  8. #==============================================================================
  9.  
  10. # Function to check if PowerShell is running elevated
  11. function Check-Elevated
  12. {
  13.   $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
  14.   $prp=new-object System.Security.Principal.WindowsPrincipal($wid)
  15.   $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  16.   $IsAdmin=$prp.IsInRole($adm)
  17.   if ($IsAdmin){
  18.     Set-Variable -Name elevated -Value $true -Scope 1
  19.   }
  20. }
  21.  
  22. function EnableDisableIF()
  23. {
  24.     begin {
  25.         "Enabling and disabling few nw interfaces"
  26.         $Script:Total = 0
  27.     }
  28.     process{
  29.         $Script:Executed=$true
  30.         if ($_.GetType() -eq [Int] ) { $DevID = $_ } else {$DevID = $_.DeviceID}
  31.         (gwmi win32_networkadapter -filter ("deviceid=" + $DevID)).disable()
  32.         trap {$Script:Executed = $false; continue}
  33.         if ($Script:Executed) {
  34.             (gwmi win32_networkadapter -filter ("deviceid=" + $DevID)).enable()
  35.             trap {$Script:Executed = $false; continue}
  36.         }
  37.         if ($Script:Executed) {$Script:Total += 1}
  38.     }
  39.     end{ ("Tried to Modify " + $Script:Total + " Interfaces") }
  40. }
  41.     
  42. Check-Elevated
  43. if (!$elevated) {Write-Warning "Not much advantage running as non-admin"; return}
  44.  
  45. #This should work in most cases even when network interface has been disabled for some reason
  46. $(gwmi win32_networkadapter) | ?{$_.MACAddress -ne $null} | EnableDisableIF
  47.  
  48. #I will prefer using above one, but this one can alse be used
  49. #gwmi win32_networkadapter -Filter "NetEnabled=true"  | EnableDisableIF
  50.  
  51. # Use below if you know interface id. Uncomment & change interface id to use it
  52. # 7 | EnableDisableIF

Today, while fixing some other issue, I tried Airtel NetXpert trouble-shooter randomly and issue got fixed !!! Airtel NetXpert is @ "E:\Program Files (x86)\Airtel\NetXpert\agent\bin\bcont.exe" /p nxpclient” in my x64 system. Most of the people may have it @ “C:\Program Files\Airtel\NetXpert\agent\bin\bcont.exe" /p nxpclient”.

Airtel NetXPert Properties in windows


In windows 7 & windows vista, it will require to be run from inside administrator login. This is bad design choice, but anyway.

 

 

Run it when there is no network available. That should show below screens in succession

 

Airtel NetXPert Startup screen testing connection

Be patient here for some time to get below screen.Airtel NetXPert Startup screen Troubleshooting link

 

 

 

 

Click on “Get Connected” and that should take you to Airtel NetXPert Startup screen Troubleshooting screen

 

Be patient with “Connection detection” screen and very soon you will see this screen offering to reset your network connection. Allow it to do so and done. Reboot machine to believe yourself.