How to create GUI in Monad?

Hey guys! Sometimes you need to create some GUI – msgbox, inputbox etc… Till now it was really problem if you needed something more advanced – for example checkboxes etc. With Monad it is quite easy! And thats because you can use .net… In fact it is similar to creating normal program!


[Reflection.Assembly]::LoadWithPartialName(”System.Windows.Forms”)


$Form = New-Object System.Windows.Forms.Form


$Button = New-Object System.Windows.Forms.Button


$Form.Text = “You didnt clicked yet”


$Button.Text = “Click here!”


$Button.Add_Click({$Form.Text = “You clicked!})


$Form.Controls.Add($Button)


$Form.ShowDialog()

Sometimes quite problem – file that came from network wont run in silent mode :(

I sometimes encountered this problem – message This file is from network and it wont run until user manually selected to allow it…


Today I encountered the same problem – so I tried to find really simple solution and now I want to share with you :)


As you maybe know, this information is stored in ADS – Alternate Data Stream. If you are interested in this, I could make standalone post dedicated to this topic.


So I tried little trick and it worked like a charm :) I know it is not good solution, however I needed to use it remotely and only once :)


File.exe — this is file with ADS information about network


 


Ren File.exe Temp.exe


Type Temp.exe File.exe


 


And thats it! :) As I said – I was looking for really simple solution and I found it…

Interview with Johan Arwidmark about deployment

Here we go! This is second interview, now with Johan Arwidmark and we talked about deployment… As you can see, Johan have same opinion as me about availability of WinPE ;)


1.) What tools are you missing most in deployment today?


 Multicast, offline image editing (when using SMS OSD), good driver injection tools, support for multiple partition handling (when using SMS OSD) and Windows PE free for all Windows Users…


 


2.) What are your favourite upcoming deployment technologies? SMS v4, Monad, WIM or something absolutely else?


 This would be all technologies using the new WIM format (WDS, SMS v4 and Ximage)


 


3.) What do you think is the biggest problem with deployment today? I mean like non-msi installers, profile migrations etc…


 Windows PE is not available for all Windows customers


 


4.) What are your favourite tools for deployment? I mean everything including 3rd party tools/support tools (IDE…) etc.


 SMS 2003 OSD (with ZTI from BDD 2.5) for clients and ADS 1.1 for servers

JIT Setup – really nice feature and most people dont know about it!

Well, when I talked with Noise in discussion under one of my previous posts, I decided I will write something about this feature. It is called Active Setup.


When new user logged on first time, their profile is created from Default user and ntuser.dat from default user… However there are some things that you cant find in default user – for example icons for Outlook Express. Most administrators dont want to have these icons – mostly because they are using more robust email client like outlook.


Most of these administrators just left them where they are. However how are these icons created?


When you look to HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components, you will see a pack of GUIDs –


every GUID here means what to do when new profile is created. The most important value is StubPath – it is path to command to execute. When this is not available, it will just ignore it.


Lets try small experiment – first locate key {6BF52A52-394A-11d3-B153-00C04F79FAA6} – it is key responsible for creating WMP icon. When you change the name of StubPath (for example DisableStubPath), the icons wont create. Neat, right? :)


Now you know how to disable certain components – however there is of course another use for them – you can create new!


For example you have application, that is using per-user settings. You want to specify default settings and you cant use HKLM\All users.


If you dont know how to create GUID, you can use my script:


strGuid = Left(CreateObject(“Scriptlet.TypeLib”).Guid, 38)
strInterpreter = Wscript.FullName
strInterpreter = InStr(strInterpreter,”cscript”)
If strInterpreter = 0 Then
 InputBox “Generated GUID:”, “GUID Generator”, strGuid
Else
 Wscript.Echo strGUID
End If


  1. create new key containing GUID.
  2. create file test.cmd with content “mkdir c:\test“ in c:\temp
  3. create value StubPath with path to your script, that will create this settings. In our example it will be “C:\Temp\test.cmd“
  4. create value ComponentID with any name you prefer. For example “Test active setup“
  5. Last needed value is IsInstalled. It should be REG_DWORD with value 1.

Now try to log as new user… Is it working? :)

You think you know everything about registry? :)

Well, I had discussion with one guy today – it was really horrible, he was from government… I thought that he knew everything about registry. This is what he told me:


“I know everything! I am IT professional you know… For example I can change your wallpaper through registry!”


Because I really hate this baby administrators (it doesnt mean I hate people that are not real professional – I hate people that think they know everything, however their knowledge is really miserable), I kindly asked him if he know what are for example REG_QWORD or REG_LINK (I though he at least knows about different structures like REG_SZ or REG_DWORD)…


Of course he was not able to say anything about it, he just said that real professional dont need this kind of informations and leaved the room quickly.


However what I wanted to speak about is REG_LINK, because I found out I didnt mentioned it before.


REG_LINK allows using symbolic links in registry – quite neat, right? :)


Typical example of usage is HKCU (mapped to HKU\<SID>) or CurrentControlSet (mapped to ControlSet###)… I am sure you can find many usage for this little registry type, like centralized per-user settings etc….


I am using it mostly using APIs, however there is at least one tool available: http://www.ntinternals.net/regln


Did you know about this? Are you interested in more informations similar to this?

Help! How to change screen resolution in batch/script???

Well, I encountered this problem – I am not able to change screen resolution using script :(


I dont want (yet) to use external utilities like multires, I want to find a way to do it using native command – I found function ChangeDisplaySettingsA in user32.dll, however I am not able to call it right way :(


I tried this: rundll32 user32.dll,ChangeDisplaySettingsA 1280,1024,60


Any ideas? :(

How to search in Active Directory and few more tricks… :)

Well, I have funny request today – we have OU PC with subOUs Desktops/Notebooks and suOUs Win2k and WinXP inside them.. I had to write script, that will move computer account to these OUs based on


a.) Computer type (notebook/desktop)
b.) installed OS (Win2k/WinXP)


So the structure is


—Desktop — WinXP


                  — Win2k


—Notebooks — WinXP


                       — Win2k


 


Here is the script I created (it is working like a charm :)) :


‘Move PC to OU
‘Martin Zugec
‘3.10.2005


Set objShell = WScript.CreateObject(“WScript.Shell”)
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\.\root\cimv2″)
Set arrayChassis = objWMIService.ExecQuery(“Select * from Win32_SystemEnclosure”)
Set objNetwork = CreateObject(“Wscript.Network”)
Set objRootDSE = GetObject(“LDAP://RootDSE“)


Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand = CreateObject(“ADODB.Command”)


objConnection.Provider = “ADsDSOObject”
objConnection.Open


strDC = objRootDSE.Get(“dnsHostName”)
strDomain = objRootDSE.Get(“DefaultNamingContext”)


strComputerName = objNetwork.ComputerName


Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = “<LDAP://” & strDomain & “>;(&(objectClass=computer)(objectCategory=computer)(cn=” & strComputerName & “));distinguishedName;subTree”
Set objResult = objCommand.Execute
Do Until objResult.EOF
 strSourceOU = objResult.Fields(“distinguishedName”)
 objResult.MoveNext
Loop



TargetOU = GetOS()
   
For Each objChassis in arrayChassis
    For  Each strChassisType in objChassis.ChassisTypes
        Select Case strChassisType
            Case 3 ‘ Desktop
             Call MoveComputer(TargetOU, “Desktopy”)
            Case 8 ‘ Notebooky
             Call MoveComputer(TargetOU, “Notebooky”)
        End Select
    Next
Next


Function GetOS()
    Dim strVer : set strVer = objShell.exec(“%comspec% /c ver”)
    Dim sResults
    sResults = strVer.stdout.readall
    Select Case True
       Case InStr(sResults, “Windows 2000″) > 1
         GetOS = “Win2K”
       Case InStr(sResults, “Windows XP”) > 1
         GetOS = “WinXP”
       Case Else
         GetOS = “Unknown”
    End Select
End Function


Function MoveComputer(TargetOU, ComputerType)
 Set objTargetOU = GetObject(“LDAP://OU=” & TargetOU & “,OU=” & ComputerType & “,OU=PC,” & strDomain)
 Set objMoveComputer = objTargetOU.MoveHere (“LDAP://” & strDC & “/” & strSourceOU, “CN=” & strComputerName)
End Function

Deployment presentation no.3: User profiles

Hey guys!


As maybe some of you know, I am working on series of (free) presentations about (free) deployment tools & techniques.


First two part were successful – right now I am preparing third part, which will be about user accounts and application installation.


Why am I telling you about this? Because I would like to ask you to help… Bring some new ideas, you experiences etc.


So I will share with you informations I want to provide there.


User accounts – I want to talk about different aspects of user profiles.


Local user profiles, roaming profiles, redirecting directories… I want to describe the difference between w2k “Wipe&Load” method of roaming profiles and wxp “Merge” method…


Next I would like to talk about how profiles are working – detecting SID, ProfileImagePath, mapping ntuser.dat to HKU\SID and HKU\SID to HKCU etc…


Also quite important will be section about Default user/All users… Informations like that you can use domain Default user (just create Default user in NetLogon) etc.. Here I have one question – have anyone tried to redirect All users directory to network? I think it should be possible, however never tried it.


Also important part about modifying profiles – how to load HKCU for different user, how to modify Just-in-time setup (like when Outlook Express icons are automatically generated), methods for modifying Default user…


 


So right now I am waiting for your comments :) What do you miss in this list, what are your experiences, tips&tricks etc…


Hope so you wont let me down :D I am always interesting in finding new informations/ideas…