Skip to main content

Posts

Showing posts from August, 2009

Windows name to ip resolution order

Oder of resolution for TCP/IP names to IP for Windows environment:  Local cached information. Can be cleared using ipconfig /flushdns.  Hosts file DNS server NetBIOS over TCP/IP In older versions of Windows up to NT 4.0, the priority can be configured through system.ini section [DNS]. The said section cannot be found in XP SP3, it might be still working and defaults normal resolution order if the section is not defined. Resources: Link 1 Link 2 ~ts

SHGetFolderLocation C++ sample code

Original code is from MSDN . Sample code demonstrates how to use  SHGetFolderLocation in C++. #include #include #include #include int main() {     IShellFolder *psfParent = NULL;     LPITEMIDLIST pidlSystem = NULL;     LPCITEMIDLIST pidlRelative = NULL;     STRRET strDispName;     TCHAR szDisplayName[MAX_PATH];     HRESULT hr;     hr = SHGetFolderLocation(NULL, CSIDL_DESKTOP, NULL, NULL, &pidlSystem);     if (!SUCCEEDED(hr))     {         std::cout << "hr bad" << std::endl;         return -1;     }     hr = SHBindToParent(pidlSystem, IID_IShellFolder, (void **) &psfParent, &pidlRelative);     if(SUCCEEDED(hr))     {         hr = psfParent->GetDisplayNameOf(pidlRelative, SHGDN_NORMAL, &strDispName);         hr = StrRetToBuf(&strDispName, pidlSystem, szDisplayName, sizeof(szDisplayName));         std::wcout << "SHGDN_NORMAL - " < << '\n';     }     psfParent->Release();     CoTaskMemFree(pidlSyste

SHGetFolderLocation

Sample code on how to use SHGetFolderLocation, shamelessly copied from this link . This code was verified to work in Windows 2000 and VB SP6. Private Declare Function SHGetFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ppidl As Long) As Long Private Declare Function SHBrowseForFolder Lib "shell32.dll" (lpbi As BROWSEINFO) As Long Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long) Private Type BROWSEINFO hwndOwner As Long pidlRoot As Long pszDisplayName As String lpszTitle As String ulFlags As Long lpfn As Long lParam As Long iImage As Long End Type Private Sub Command1_Click() ' This code is licensed according to the terms and conditions listed here. ' Open the Browse

Converting CString to CComBSTR

Code below shows how to convert CString to CComBSTR. // CComBSTR.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include int _tmain(int argc, _TCHAR* argv[]) { CComBSTR szDbgMsg; CString sMsg; sMsg = _T("Hello world new"); sMsg.Format(_T("%s : %d"), sMsg, 12); //szDbgMsg = L"Hello world "; szDbgMsg = sMsg.GetBuffer(); CW2A printstr(szDbgMsg); std::wcout << ((CString)szDbgMsg).GetBuffer() << std::endl; std::wcout << sMsg.GetBuffer() << std::endl; return 0; } ~ts

List all installed applications in a machine

The script below will list and save all installed applications to a csv file. Save the script as say, save.vbs. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.CreateTextFile("c:\software.csv", True) strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colSoftware = objWMIService.ExecQuery _ ("Select * from Win32_Product") objTextFile.WriteLine "Caption" & vbtab & _ "Description" & vbtab & "Identifying Number" & vbtab & _ "Install Date" & vbtab & "Install Location" & vbtab & _ "Install State" & vbtab & "Name" & vbtab & _ "Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _