Friday, June 6, 2014

sync time between 2 windows servers

1:Make sure
HKLM\SYSTEM\CurrentControlSet\services\W32Time\Parameters\Type  value is NT5DS

2:Then type this at an elevated command prompt:
w32tm /config /manualpeerlist:10.0.0.1,0x8 /syncfromflags:MANUAL /update

3:Then restart the Windows Time service and type this to confirm it worked:
w32tm /query /status

Tuesday, June 3, 2014

Install /Unstall .INF driver visual studio setup project

I created a minifilter driver for log /block file access. and need install the driver use visual studio setup project.
Create custom action for install/uninstall .INF driver.

rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 .\xxx.inf

rundll32 setupapi,InstallHinfSection DefaultUninstall 132 " +chr(34) + installdir +"Drivers\xxx.inf" + chr(34)


Function InstallDriver()
on error resume next
Dim WshShellInstallTest, oExec ,windowsdir
Set WshShellInstallTest = CreateObject("WScript.Shell")
if (Err.Number <> 0) Then
MsgBox "WScript.Shell" & Err.Number & " " & Err.Description
Err.Clear
end if
Dim installdir
installdir = Session.Property("CustomActionData")
if (Err.Number <> 0) Then
MsgBox "CustomActionData" & Err.Number & " " & Err.Description
Err.Clear
end if
WshShellInstallTest.CurrentDirectory = installdir + "Drivers"

Dim InstallUtilPath
'InstallUtilPath = "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 " + chr(34) +installdir+ "Drivers\xxx.inf" + chr(34)
InstallUtilPath = "rundll32 syssetup,SetupInfObjectInstallAction DefaultInstall 128 .\xxx.inf" 
MsgBox InstallUtilPath
WshShellInstallTest.Run InstallUtilPath , 0, true
if (Err.Number <> 0) Then
MsgBox "WshShell" & Err.Number & " " & Err.Description
Err.Clear
end if

set WshShellInstallTest = nothing

End Function



Function UnInstallDriver()
on error resume next
Dim WshShellInstallTest, oExec ,windowsdir
Set WshShellInstallTest = CreateObject("WScript.Shell")
if (Err.Number <> 0) Then
MsgBox "WScript.Shell" & Err.Number & " " & Err.Description
Err.Clear
end if
Dim installdir
installdir = Session.Property("CustomActionData")
if (Err.Number <> 0) Then
MsgBox "CustomActionData" & Err.Number & " " & Err.Description
Err.Clear
end if
WshShellInstallTest.CurrentDirectory = installdir + "Drivers"
Dim InstallUtilPath
InstallUtilPath = "Fltmc unload bfaccess"
WshShellInstallTest.Run InstallUtilPath , 0, true
InstallUtilPath = "rundll32 setupapi,InstallHinfSection DefaultUninstall 132 " +chr(34) + installdir +"Drivers\xxx.inf" + chr(34)
if (Err.Number <> 0) Then
MsgBox "WshShell" & Err.Number & " " & Err.Description
Err.Clear
end if

set WshShellInstallTest = nothing

End Function

Thursday, February 27, 2014

About Msi Installer impersonate problem.

About Msi Installer impersonate problem.
I using vs2010 create installer project to update GPO, the problem is even I run as administrator, there still have permission issue.
The script no problem, when I just run script, it worked fine. but the custom action
when I run the import the GPO backup,
return "Name translation: Could not find the name or insufficient right to see name. "
So I think it is the Installer impersonate problem ,It not run as Administrator or not get full permission.
I search online , find a helpful script, update custom action NoImpersonate, but it run under SYSTEM, it not my need.
Custom Action In-Script Execution Options
http://msdn.microsoft.com/en-us/library/aa368069(v=vs.85).aspx
Mailbag: How to set the NoImpersonate flag for a custom action in Visual Studio 2005
http://blogs.msdn.com/b/astebner/archive/2006/10/23/mailbag-how-to-set-the-noimpersonate-flag-for-a-custom-action-in-visual-studio-2005.aspx

just change a little bit, it worked find.
if with NoImpersonate :
// NoImpersonate.js <msi-file>
// Performs a post-build fixup of an msi to change all deferred custom actions to NoImpersonate
// Constant values from Windows Installer
var msiOpenDatabaseModeTransact = 1;
var msiViewModifyInsert         = 1
var msiViewModifyUpdate         = 2
var msiViewModifyAssign         = 3
var msiViewModifyReplace        = 4
var msiViewModifyDelete         = 6
var msidbCustomActionTypeInScript       = 0x00000400;
var msidbCustomActionTypeNoImpersonate  = 0x00000800
var msidbCustomActionTypeTSAware  = 0x00004000
if (WScript.Arguments.Length != 1)
{
 WScript.StdErr.WriteLine(WScript.ScriptName + " file");
 WScript.Quit(1);
}
var filespec = WScript.Arguments(0);
var installer = WScript.CreateObject("WindowsInstaller.Installer");
var database = installer.OpenDatabase(filespec, msiOpenDatabaseModeTransact);
var sql
var view
var record
try
{
 sql = "SELECT `Action`, `Type`, `Source`, `Target` FROM `CustomAction`";
 view = database.OpenView(sql);
 view.Execute();
 record = view.Fetch();
 while (record)
 {
     if (record.IntegerData(2) & msidbCustomActionTypeInScript)
     {
         record.IntegerData(2) = record.IntegerData(2) | msidbCustomActionTypeNoImpersonate;
   'change to
   record.IntegerData(2) = record.IntegerData(2) & ~msidbCustomActionTypeNoImpersonate;
         view.Modify(msiViewModifyReplace, record);
     }
        record = view.Fetch();
 }
 view.Close();
 database.Commit();
}
catch(e)
{
 WScript.StdErr.WriteLine(e);
 WScript.Quit(1);
}