Strict Standards: Redefining already defined constructor for class wpdb in /var/www/myfoto.se/jbits.se/blog/wp-includes/wp-db.php on line 56

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/myfoto.se/jbits.se/blog/wp-includes/cache.php on line 36

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /var/www/myfoto.se/jbits.se/blog/wp-includes/cache.php on line 384

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 541

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 560

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 659

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el($output) in /var/www/myfoto.se/jbits.se/blog/wp-includes/classes.php on line 684

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/myfoto.se/jbits.se/blog/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /var/www/myfoto.se/jbits.se/blog/wp-content/plugins/code-highlighter/codehighlighter.php on line 42

Deprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead in /var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php on line 82
jbits.se <br /> <b>Deprecated</b>: preg_replace() [<a href='http://php.net/manual/en/function.preg-replace'>function.preg-replace</a>]: The /e modifier is deprecated, use preg_replace_callback instead in <b>/var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php</b> on line <b>82</b><br /> » VBScript

jbits.se

Jörgen Björkmans blog

Archive for the ‘
Deprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead in /var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php on line 82
VBScript’ Category

Mar
16

Script to disable nic powersaving

Posted by jbjorkman on March 16, 2010 under VBScript

Option Explicit
Const HKLM = &H80000002
Dim oShell, oReg, oWMI, aryNICs, oNIC, strNICName, strNICId, intPNPCap, intNewPNPCap,strResultSet oShell = WScript.CreateObject("Wscript.Shell")
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set aryNICs = oWMI.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each oNIC in aryNICs
strNICid=Mid(oNIC.Caption,6,4)
strNICName=Mid(oNIC.Caption,12,len(oNIC.Caption)-10)
oReg.GetDWORDValue HKLM, "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\" & strNICid & "\","PnPCapabilities",intPNPCap
if (intPNPCap and 56)=56 then
strResult=strResult & "Powersaving already disabled for " & strNICName & vbCRLF
else
oReg.SetDWORDValue HKLM, "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\" & strNICid & "\","PnPCapabilities",(intPNPCap or 56)
oReg.GetDWORDValue HKLM, "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\" & strNICid & "\","PnPCapabilities",intNewPNPCap
if intNewPNPCap=intPNPCap then
strResult=strResult & "Couldn't change settings for " & strNICName & vbCRLF
else
strResult=strResult & "Disabling Powersave for " & strNICName & "(" & intPNPCap & ">" & intNewPNPCap & ")" & vbCRLF
end if
end if
Next

oShell.popup strResult,10,"Disabe NIC Powersaving",64

Set oReg = Nothing
Set oWMI = Nothing

Aug
01

CertBackup.vbs

Posted by jbjorkman on August 1, 2009 under VBScript, Windows

'************ You have to have capicom.dll downloaded and registered...
' Download and install: http://www.microsoft.com/DownLoads/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&displaylang=en
' run regsvr32 "C:\Program Files\Microsoft CAPICOM 2.1.0.2 SDK\Lib\X86\capicom.dll"

Option Explicit ' Explicit Declaration of Variables

' *** CAPICOM Constants
Const CAPICOM_CERTIFICATE_SAVE_AS_CER = 1
Const CAPICOM_CERTIFICATE_SAVE_AS_PFX = 0
Const CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN = 1
Const CAPICOM_MEMORY_STORE  = 0 ' The store is a memory store. Any changes in the contents of the store are not persisted.
Const CAPICOM_LOCAL_MACHINE_STORE  = 1 ' The store is a local machine store. Local machine stores can be read/write stores only if the user has read/write permissions. If the user has read/write permissions and if the store is opened read/write, then changes in the contents of the store are persisted.
Const CAPICOM_CURRENT_USER_STORE  = 2 ' The store is a current user store. A current user store may be a read/write store. If it is, changes in the contents of the store are persisted.
Const CAPICOM_ACTIVE_DIRECTORY_USER_STORE  = 3 ' The store is an Active Directory store. Active Directory stores can be opened only in read-only mode. Certificates cannot be added to or removed from Active Directory stores.
Const CAPICOM_SMART_CARD_USER_STORE  = 4 ' Stores support smart card–based certificate stores. The store is the group of present smart cards. Introduced in CAPICOM 2.0.
Const CAPICOM_MY_STORE = "My" ' This store is used for a user's personal certificates.
Const CAPICOM_CA_STORE = "CA" ' CA store. This store is used to store intermediate CA certificates.
Const CAPICOM_ROOT_STORE = "Root" ' Root store. This store is used to store the root CA and self-signed, trusted certificates.
Const CAPICOM_OTHER_STORE = "AddressBook" ' AddressBook store. This store is used to keep the certificates of others.
Const CAPICOM_STORE_OPEN_READ_ONLY = 0

' *** Script Constants
Const Title="CertBack (c) JBjorkman 2009"
Const Version="0.9"

' *** Script variable declarations
Public IE        ' Declare Public Variable for events
Dim oStore        ' CAPICOM Store object variable

Dim strPFXPasswd
Dim strPath
Dim oFolder

Dim StatusHTML

' *** Setup CAPICOM Store object
on error resume next
Set oStore = CreateObject ("CAPICOM.Store")
if Err.Number <> 0 Then
MsgBox "CAPICOM not detected" & vbCRLF & "You have to have capicom.dll downloaded and registered, see script header for details."
Wscript.Quit(1)
End if

' *** Show browse for folder dialog to select where to save Certificates

Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0,"Select where to dump certificates",0)

If oFolder Is Nothing Then ' User clicked Cancel
Wscript.Quit
End If

strPath=oFolder.Self.Path

GetPasswd "Enter password for pfx encryption",strPFXPasswd

' *** Setup IE Window
IEGUISetup
CreateObject("WScript.Shell").AppActivate IE.Document.Title

DumpCerts CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE
DumpCerts CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE
DumpCerts CAPICOM_CURRENT_USER_STORE, CAPICOM_CA_STORE
DumpCerts CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_CA_STORE
DumpCerts CAPICOM_CURRENT_USER_STORE, CAPICOM_ROOT_STORE
DumpCerts CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_ROOT_STORE

' *** Loop until false
CreateObject("WScript.Shell").popUp "Finished dumping certificates...",2

IE.Quit
Set oStore=Nothing
Set IE=Nothing
WScript.Quit

' ***** End of Main Program *****

' ***** Handle user closing IE Window
Sub IE_onQuit
Set oStore=Nothing
Set IE=Nothing
WScript.Quit
End Sub

' ***** Init IE GUI
Sub IEGUISetup()
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Navigate "about:blank"
WScript.Sleep 100
Do until IE.ReadyState = 4    ' Wait until Complete (READYSTATE_COMPLETE=4)
WScript.Sleep 100
Loop

IE.MenuBar=False
IE.ToolBar=False
IE.StatusBar=False
IE.Resizable=False
IE.AddressBar=False
IE.Width=975
IE.Height=IE.Document.ParentWindow.Screen.Height-50
IE.Left=(IE.Document.ParentWindow.Screen.Width-IE.Width)/2
IE.Top=10

IE.Document.Title = title

IE.Document.Open
IE.Document.Writeln "<html>"
IE.Document.Writeln "<head>"
IE.Document.Writeln "<title>" & title & "</title>"
IE.Document.Writeln "<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"">"
IE.Document.Writeln "<style type=""text/css"">"
IE.Document.Writeln "<!--"
IE.Document.Writeln ".Title {"
IE.Document.Writeln "    color: #FFFFFF;"
IE.Document.Writeln "    font-family: Verdana, Arial, Helvetica, sans-serif;"
IE.Document.Writeln "    font-weight: bold;"
IE.Document.Writeln "}"
IE.Document.Writeln ".def {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; font-weight: bold; color: #f0f0c0; cursor: 'default';}"
IE.Document.Writeln ".status {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; font-weight: bold; color: #e0e0c0; cursor: 'default';}"
IE.Document.Writeln ".private {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9px; font-weight: bold; color: #e02020; cursor: 'default';}"
IE.Document.Writeln ".title {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; color: #ffffff; cursor: 'default';}"
IE.Document.Writeln "-->"
IE.Document.Writeln "</style>"
IE.Document.Writeln "</head>"
IE.Document.Writeln "<body bgcolor=""#204020"">"
IE.Document.Writeln "<p align=""center""Title"">" & title & " v" & version & "</p>"
IE.Document.Writeln "<SPAN name=""MainTable"" id=""MainTable"">"
IE.Document.Writeln "<table name=""MainTable"" id=""MainTable"" width=""900"" border=""0"" cellpadding=""0"" cellspacing=""0"" bgcolor=""#e0e0c0"">"
IE.Document.Writeln "  <tr bgcolor=""#406040"" valign=""top"">"
IE.Document.Writeln "    <td width=""200""><div align=""left""><span name=""LOC"" id=""LOC""def"">Location</span></div></td>"
IE.Document.Writeln "    <td width=""600""><div align=""left""><span name=""CER"" id=""CER""def"">Certificate</span></div></td>"
IE.Document.Writeln "    <td width=""100""><div align=""left""><span name=""ACT"" id=""ACT""def"">Action</span></div></td>"
IE.Document.Writeln "  </tr>"
IE.Document.Writeln "</table>"
IE.Document.Writeln "</SPAN>"
IE.Document.Writeln "<SPAN name=""Status"" id=""Status""status"">"
IE.Document.Writeln "</SPAN>"
IE.Document.Writeln "</body>"
IE.Document.Writeln "</html>"
IE.Visible = True
End Sub

' *** Sub to dump certificates
Sub DumpCerts(store,storetype)
Dim oCert
Dim strCertName
Dim strfname
Dim strCompName
Dim strDate
Dim strType

StrCompName=WScript.CreateObject("WScript.Network").ComputerName  ' Get Computername
StrDate=Year(Now) & right("0" & Month(Now),2) & right("0" & Day(Now),2) ' Get date (YYYYMMDD)

oStore.Open store,storetype, CAPICOM_STORE_OPEN_READ_ONLY

Select case store
case 0 strType="Memory-" & storetype
case 1 strType="Machine-" & storetype
case 2 strType="User-" & storetype
case 3 strType="AD-" & storetype
case 4 strType="SmartCard-" & storetype
end select

For Each oCert in oStore.Certificates
on error resume next
strCErtName="Unknown"
strCertName=left(oCert.SubjectName,instr(oCert.SubjectName,",")-1)
strCertName=replace(strCertName,"CN=","")
strCertName=replace(strCertName,"OU=","")
strCertName=replace(strCertName,"*","x")
strCertName=replace(strCertName," ","-")
strCertName=replace(strCertName,"/","-")
strCertName=replace(strCertName,"\","-")
strCertName=replace(strCertName,"""","-")
strCertName=replace(strCertName,".","-")
on error goto 0

strfname=strCompName & "-" & strDate & "_" & strType & "_" & strCertName

if oCert.HasPrivateKey then ' These certificates we have a private key for, we'll save them as pfx
IE.Document.all.item("Status").innerHTML="<SPAN class='private'>Saving: " & strfname & ".pfx</SPAN><BR>" & IE.Document.all.item("Status").innerHTML
oCert.Save strPath & "\" & strfname & ".pfx", strPFXPasswd, CAPICOM_CERTIFICATE_SAVE_AS_PFX, CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN
else
IE.Document.all.item("Status").innerHTML="Saving: " & strfname & ".cer<BR>" & IE.Document.all.item("Status").innerHTML
oCert.Save strPath & "\" & strfname & ".cer",, CAPICOM_CERTIFICATE_SAVE_AS_CER
end if
Next
End Sub

Function GetPasswd( strPrompt, byref strPasswd)
Const CmplxRegExp="^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$" ' Complexity requirements regular expression
Dim oIEPwd
Dim oRegExp
Dim bFinished
Set oIEPwd = CreateObject( "InternetExplorer.Application" )
With oIEPwd
.Navigate "about:blank" : .Document.Title = strPrompt
.Toolbar = False : .Resizable = False : .StatusBar = False
.Width= 400 : .Height =150
.Left=(oIEPwd.Document.ParentWindow.Screen.Width-oIEPwd.width)\2
.Top=(oIEPwd.Document.ParentWindow.Screen.Height-oIEPwd.height)\2
End with
Do While oIEPwd.Busy
WScript.Sleep 100
Loop
oIEPwd.Document.Body.InnerHTML = "<DIV ALIGN=""center"">" & strPrompt & "<BR>" _
& "<INPUT TYPE=""password"" SIZE=""25"" ID=""Passwd""><BR>" _
& "<INPUT TYPE=""password"" SIZE=""25"" ID=""Passwd2""><BR>" _
& "<INPUT TYPE=""hidden"" ID=""OK"" NAME=""OK"" VALUE=""0"">" _
& "<INPUT TYPE=""submit"" VALUE="" OK "" OnClick=""VBScript:OK.Value=1""></DIV>"
oIEPwd.Visible = True

oIEPwd.document.all.Passwd.focus

On Error Resume Next

bFinished=False
Do
Do While oIEpWD.Document.All.OK.Value = 0
WScript.Sleep 100
If Err Then
GetPasswd=False : strPasswd="" : oIEPwd.Quit : Set oIEPwd = Nothing : Exit Function
End if
Loop
if oIEPwd.Document.All.Passwd.Value<>oIEPwd.Document.All.Passwd2.Value then
MsgBox "Passwords don't match, reenter please..." : oIEPwd.Document.All.Passwd.Value="" : oIEPwd.Document.All.Passwd2.Value="" : oIEpWD.Document.All.OK.Value=0 : oIEPwd.document.all.Passwd.focus
else
Set oRegExp = new RegExp
oRegExp.Pattern = CmplxRegExp
if oRegExp.Test(oIEPwd.Document.All.Passwd.Value) then ' Check our complexity requirements
GetPasswd = True
strPasswd=oIEPwd.Document.All.Passwd.Value
bFinished=True
else
MsgBox "Password does not meet complexity requirements, make sure it tests true against:" & vbCRLF & CmplxRegExp : oIEPwd.Document.All.Passwd.Value="" : oIEPwd.Document.All.Passwd2.Value="" : oIEpWD.Document.All.OK.Value=0 : oIEPwd.document.all.Passwd.focus

end if
end if
loop while bFinished=False

On Error Goto 0

oIEPwd.Quit
Set oIEPwd = Nothing
End Function

Apr
03

Cert Backup

Posted by jbjorkman on April 3, 2009 under VBScript, Windows

Option Explicit
'************ You have to have capicom.dll downloaded and registered...
on error resume next
Const SavePath="C:\System\ISA-Backups\Certs\"
Const CAPICOM_CERTIFICATE_SAVE_AS_PFX = 0
Const CAPICOM_CURRENT_USER_STORE  = 2
Const CAPICOM_EKU_CLIENT_AUTH = 2
Const CAPICOM_EKU_CODE_SIGNING = 3
Const CAPICOM_EKU_EMAIL_PROTECTION = 4
Const CAPICOM_EKU_SERVER_AUTH = 1
Const CAPICOM_EKU_OTHER = 0
Const CAPICOM_EXPORT_DEFAULT = 0
Const CAPICOM_CERTIFICATE_INCLUDE_CHAIN_EXCEPT_ROOT = 0
Const CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN = 1
Const CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY = 2
Const CAPICOM_LOCAL_MACHINE_STORE  = 1
Const CAPICOM_MY_STORE = "My"
Const CAPICOM_STORE_OPEN_EXISTING_ONLY = 128
Const CAPICOM_STORE_OPEN_READ_ONLY = 0
Const CAPICOM_STORE_SAVE_AS_PFX = 2
Const CR_DISP_ISSUED  = &H3
Const CR_OUT_CHAIN = &H100
Const CR_OUT_BASE64 = &H1
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = &H20000
Const CR_IN_BASE64  = &H1
Const CR_IN_PKCS10  = &H100

Dim oCert, oStore
Dim strDate
Dim strCmp
Dim strCertName
Dim strfname
Dim strPasswd

Set oStore = CreateObject ("CAPICOM.Store")
if Err.Number <> 0 Then
wscript.echo "CAPICOM NOT detected"
Wscript.Quit(1)
End if

StrDate=Year(Now) & "-" & right("0" & Month(Now),2) & "-" & right("0" & Day(Now),2)
StrCmp=WScript.CreateObject("WScript.Network").ComputerName

oStore.Open CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE, CAPICOM_STORE_OPEN_READ_ONLY

strPasswd=Inputbox("Enter password to encrypt pfx with")

For Each oCert in oStore.Certificates
strCertName=left(oCert.SubjectName,instr(oCert.SubjectName,",")-1)
strCertName=replace(strCertName,"CN=","")
strCertName=replace(strCertName,"OU=","")
strCertName=replace(strCertName,"*","x")
strCertName=replace(strCertName," ","-")
strCertName=replace(strCertName,".","-")

strfname=strCmp & "-" & left(oCert.ValidtoDate,10) & "-" & strCertName

oCert.Save savePath & strfname & ".pfx", strPasswd, CAPICOM_CERTIFICATE_SAVE_AS_PFX, CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN
Next

Jan
18

Remove mailto association and replace with custom script.

Posted by jbjorkman on January 18, 2007 under VBScript, Windows

If you want to remove your default mailto association you need to manually associate
mailto with something else (a script in this example).

When you click a mailto link HKEY_CLASSES_ROOT\mailto is checked to see which associated mail program you have.
HKEY_CLASSES_ROOT is a combined view made from HKLM\Software\Classes and HKCU\Software\Classes.
HKCU\Software\Classes takes precendence because you want to be able to have user-unique associations.

Add the following to HKCU\Software\Classes\mailto
DefaultIcon\(Default) REG_EXPAND_SZ "%ProgramFiles%\INTERN~1\hmmapi.dll,1"
Shell\Open\Command\(Default) REG_EXPAND_SZ "wscript "[Path to Script]\MailAssoc.vbs"  %1

MailAssoc.vbs
Option Explicit
Dim oArgs
Dim sArg
Dim sClipText
Set oArgs=WScript.ArgumentsFor Each sArg in oArgs
  if instr(sArg,"@") then
 sClipText=sArg
 sClipText=trim(replace(lcase(sClipText),"mailto:",""))
  end if
Next
if sClipText<>"" then
  if MsgBox("Press Ok to copy address to your clipboard" & vbCRLF & sClipText,1,"No email program association found.")=1 then
    Dim oIE
    Set oIE=Createobject("internetexplorer.application")
    oIE.navigate "about:blank"
    oIE.document.parentwindow.clipboardData.setData "Text",sClipText
    oIE.quit
    Set oIE=Nothing
  end if
End if