Archive for June, 2009

add podcasts to your creative zen player

June 5, 2009

I used to use the media manager tool that creative supplied, but I think it’s easier to just use windows explorer. (this works in vista as well, but I’ll explain XP here)
1) get to your iTunes podcasts folder in one instance of explorer:
mine is at: C:\Documents and Settings\myNameHere\My Documents\My Music\iTunes\iTunes Music\Podcasts

2) open the zen in another instance of explorer
mine is at: My Computer\My Zen

3) drag a podcast mp3 file to your zen (for example My Computer\My Zen\Storage Media\Music\stocks)

4) open a playlist by clicking on it
(look in My Computer\My Zen\Storage Media\My Playlists)

5) from the zen explorer, drag a file into a playlist.

I think this is a lot faster than using the creative supplied tool, but I’m glad they supplied us with it.

How to set an environment variable by setting it in the registry

June 5, 2009

It’s easy to do a “getenv” , but you’d be surprised at how hard it is to set an environment variable.
Sorry, I’m not going to take the time to write here what I learned from some excellent explanations found at codeguru and elsewhere, but I’ll try to post those links at the last.
Basically:
1) set the current user\environment\yourstring=value in the registry
2) send a windows refresh message (this doesn’t communicate with whatever command prompts you may already have, but it will work for the calling process)
3) whatever new command prompt or process will use your new setting


LRESULT CMainDlg::OnSetMyEnvironmentValue(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CString sNetId;
GetDlgItem(IDC_NETID).GetWindowTextA(sNetId);

Handle_SetReg(sNetId);
Handle_RefreshEnvironment();
return Handle_SetEnv(sNetId);
return 0;
}

int CMainDlg::Handle_SetEnv(CString sNetId)
{
//MessageBox (sNetId, "netid", 0) ; //sNetId.GetBuffer()

// set env variable
int iRet = 0;
iRet = SetEnvironmentVariable("netid", sNetId.GetBuffer() );

if( iRet <=0 )
{
GetLastError();
return -1;
}
return 0;

}

int CMainDlg::Handle_SetReg(CString sNetId)
{
CString subKey = "Environment";
HKEY hKey;
char *m_tmpChar = new char[100];

if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_SET_VALUE, &hKey))
{
MessageBox("Error opening the key");
RegCreateKey(HKEY_CURRENT_USER, subKey,&hKey);
}

if ( RegSetValueEx(hKey, "netid" , NULL , REG_SZ, (unsigned char*)sNetId.GetBuffer() ,sNetId.GetLength() +1) )
MessageBox("Error setting the value");
RegCloseKey(hKey);

return 0;
}

// http://wiki.answers.com/Q/How_do_you_set_registry_entry_as_environment_variable
int CMainDlg::Handle_RefreshEnvironment()
{
DWORD_PTR dwReturnValue;

SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
(LPARAM) "Environment", SMTO_ABORTIFHUNG,
500, &dwReturnValue);
return dwReturnValue;
}

Here were some helpful links:
reading:
basics
http://www.codeguru.com/forum/showpost.php?p=1171365&postcount=7

REGISTRY
HKEY_CURRENT_USER\Environment
HKEY_CURRENT_USER\VolatileEnvironment
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
http://vlaurie.com/computers2/Articles/environment.htm
VISTA http://vistaonwindows.com/environment_variables.html

registry
http://www.codeguru.com/cpp/w-p/system/registry/print.php/c5793

6/4/09
helpful
http://wiki.answers.com/Q/How_do_you_set_registry_entry_as_environment_variable

looks like broadcasting the wm_settingchange won’t talk to cmd prompts
http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-03/msg05284.html

search all tables for a string

June 5, 2009

I needed to search the ‘description’ field of every table in my database for a string.
To do that, I generated a column of search commands.
Then I copied those search commands into a new query window in sql server enterprise manager and executed them. I could see which tables contained the string I was looking for.

Here is the sql to generate the column of commands. A trick is to concatenate the literal single quote string.

**********************************************
SEARCH all tables , ALL COLUMNS NAMED ‘DESCRIPTION’ FOR RECORDS CONTAINING A KEY WORD
*******************

select (‘Select ‘ + char(39) + table_name + char(39) + ‘ as TableName ,* from ‘ + table_name + ‘ where [description] like ‘ + char(39) + ‘%Back Flow%’ + char(39) + ‘ ‘ ) as copyandexecute , column_name from INFORMATION_SCHEMA.columns
where column_name = ‘Description’
order by column_name

search all stored procedures for a string

June 5, 2009

Search all stored procedures that contain some text

select specific_name , Routine_Definition from INFORMATION_SCHEMA.ROUTINES
where Routine_Definition like ‘%tblRatingSectionItemAttribute%’
— runs into a limit on string length

THIS WORKED
SELECT OBJECT_NAME(id) , [text]
FROM syscomments
WHERE [text] LIKE ‘%Back Flow%’
AND OBJECTPROPERTY(id, ‘IsProcedure’) = 1
GROUP BY OBJECT_NAME(id) , [text]