Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell VB6 not to save the layout 1

Status
Not open for further replies.

xwb

Programmer
Jul 11, 2002
6,828
GB
I work with an annoying bunch of developers. When I show them something on my console, they cannot resist rearranging the panels when they are looking at code. As a result, the system ends up with panels where I don't like them.

How do I tell Visual Studio not to save the panel layout so that it goes back to what it used to be. So far, the only method I've used when one of these screen rearrangers comes along is to open up another VB Session. When they've finished, I close their session, move the borders a bit on my dummy session and then close that.

This technique doesn't always work either as the screen rearrangers also seem to close other explorer sessions and VB sessions because the programs on the task bar confuse them.

These people are so annoying. Unfortunately, I need them to review the code before I check it in. Occassionally, I need them to help me debug code.

Is there a way of telling Visual Studio "save layout" and "restore layout"?

GNNN - why can't these people look without touching???
 
look at the files. I think it it called <project name>.vbw. Back this one up before you invite them to look and resore it afterwards.

If you work with source code control, these files are best left out, as everyone will get each other's window settings otherwise.
 
I thought they were part of the workspace like dsws in VC++. VC++ doesn't keep layouts in the dsw files.

I'll have a look at the vbws anyway. They're strange. If I modify anything in a .frm, the vbw gets updated. I have yet to look into a vbw to find out what it updates.
 
If you are talking about the layout of your project files, like form designers and code modules, the information is saved in the Project.vbw file as mentioned by Don. Making this file read-only prevents VB to update project layout when the project is closed and the layout never changes.

To preseve the layout of VBIDE itself, you should make a backup of following registry key.

HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0

All UI-related data and layout of toolbars/panels is saved in this key. Note that this key also has some subkeys which contain other information related to add-ins and designers. You need to exclude this information from the backup file. Just open the .reg file in Notepad, scroll down to the point from where the subkey data start. Delete all subkey data that follows and save the file.

From now on, whenever your UI gets messed up, just merge the reg file to registry to restore your saved layout.
 
Hypetia - your method is brilliant except for one problem: I'm not an admin user. On the standalone machines where I am an admin user, I can do the registry stuff and it works beautifully.

On machines connected to the network, I'm not an admin user. Any idea how this is done when you're not the admin user?
 
You ask an admin user to do it. Alternatively, you can get an admin user to allow you to modify the registry on network boxes. Furthermore, the sun might rise in the west tomorrow, too; one cannot prove otherwise.

All kidding aside, you can probably get with an admin user work out a way to run your routine via an exe or batch file while still preserving security. You get the right to run the program, the program gets the right to modify the registry.
 
I don't know exactly what restrictions and permissions apply to you as a regular user, but there is no harm trying the following VB code.

Start a new VB project, place two command buttons on the form and insert the following code.
___
[tt]
Option Explicit
Private Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As Any, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegQueryInfoKey Lib "advapi32" Alias "RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, lpcbClass As Long, lpReserved As Long, lpcSubKeys As Long, lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, lpcbSecurityDescriptor As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Const HKEY_CURRENT_USER = &H80000001
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2

Private Sub Form_Load()
Command1.Caption = "&Backup"
Command2.Caption = "&Restore"
End Sub

Private Sub Command1_Click()
CopyKeyValues "Software\Microsoft\Visual Basic\6.0", "Software\Microsoft\Visual Basic\Backup"
End Sub

Private Sub Command2_Click()
CopyKeyValues "Software\Microsoft\Visual Basic\Backup", "Software\Microsoft\Visual Basic\6.0"
End Sub

Private Sub CopyKeyValues(SrcKey As String, DstKey As String)
Dim hKey1 As Long, hKey2 As Long
Dim ret As Long, nCount As Long, lpType As Long, N As Long
Dim lpName As String, lpcbName As Long, lpcbNameMax As Long
Dim lpData() As Byte, lpcbData As Long, lpcbDataMax As Long
ret = RegCreateKeyEx(HKEY_CURRENT_USER, SrcKey, 0, vbNullString, 0, KEY_QUERY_VALUE, ByVal 0&, hKey1, ret)
ret = RegCreateKeyEx(HKEY_CURRENT_USER, DstKey, 0, vbNullString, 0, KEY_SET_VALUE, ByVal 0&, hKey2, ret)
ret = RegQueryInfoKey(hKey1, vbNullString, ByVal 0, ByVal 0, ByVal 0, ByVal 0, ByVal 0, nCount, lpcbNameMax, lpcbDataMax, ByVal 0, ByVal 0)
lpName = Space$(lpcbNameMax)
ReDim lpData(lpcbDataMax)
For N = 0 To nCount - 1
lpcbName = lpcbNameMax + 1
lpcbData = lpcbDataMax + 1
ret = RegEnumValue(hKey1, N, lpName, lpcbName, 0, lpType, lpData(0), lpcbData)
RegSetValueEx hKey2, lpName, 0, lpType, lpData(0), lpcbData
Next
RegCloseKey hKey1
RegCloseKey hKey2
End Sub[/tt]
___

The code allows you to saves the UI/environment related data to a backup key, which can be restored later. I at least tested it in a limited user account and it works fine.
 
Thanks - that works. I now owe the IT manager a couple of pints after having to do all the permission settings myself. All he did was type in the admin password and told me to logoff when I'd finished. Well, I suppose it was worth it. Better than rearranged screens.
 
That was quick. :) So, what permission settings did you do exactly?
 
Sorry for the late reply - been in factory acceptance tests all week. Anyway, it was a bit of a fiddle and a 2 stage thing. Sys Admin basically put their password in a public encrypted file. I wrote a program to decrypt it and issue a runas and pop in the password.

It was quite messy. Looking for a neater solution after FAT is over. Must be an equivalent of the Unix sticky bit somewhere in Windows. Can't believe they actually don't have something like that.

I know how to do it as a service but not as a standalone executable. For services, instead of running as localsystem, you change to a specific user, ask that user to type in the password and ok it. Then the service will always run as that particular user.

 
You might want to start looking into LDAP and the Active Directory.
 
I am playing with Active directory at the moment but it has to take second place to "real work".
 
Got somethine but it only works on XP Prof. Basically it is runas using the /savecred flag. The first time round, it asks the password, subsequent times it doesn't and runs as the authorized user.

More searching - haven't found anything for Win2K server yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top