Re: [python-win32] Problem creating a shortcut

2008-05-16 Thread Tim Golden

Sorry, missed this one going through. Looks like
Roger's hit the nail on the head, though. Bizarre
behaviour by the IShellLink interface: I can't find
any kind of reference to this but I assume that
since the Path attribute of the link should *only*
contain an executable, there's no need for the
quotes -- which then confuse it when they're there
as it tries to make the executable into an absolute
path.

One small comment, Mike. Since you're using the
winshell module -- which I assume is the one from
my site -- why not use its CreateShortcut function?
It's basically just a light wrapper around the IShellLink
functionality which someone else mentioned:


import os, sys
import winshell

winshell.CreateShortcut (
Path=os.path.join (winshell.desktop (), "shortcut.lnk"),
Target=r"c:\Program Files\Mozilla Firefox\firefox.exe",
Arguments="http://localhost";,
Description="Open http://localhost with Firefox"
)



But maybe you're using the WScript.Shell functionality
elsewhere as well?

TJG

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem creating a shortcut

2008-05-16 Thread Mike Driscoll

Roger,
Mike 
Driscoll wrote:

Hi,

I've had this niggling issue from time to time. I want to create a
shortcut on the user's desktop to a website that specifically loads
Firefox even if Firefox is not the default browser.

I usually use COM as it allows very specific settings of the shortcut,
such as the Working Directory and the Target Path. However, the
following will not work for some reason:



import win32com.client
import winshell

shell = win32com.client.Dispatch('WScript.Shell')
userDesktop = winshell.desktop()

shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk')
shortcut.Targetpath = r'"C:\Program Files\Mozilla Firefox\firefox.exe"
https:\www.myCompanyWebsite.com\ 
auth\preauth.php'

shortcut.WorkingDirectory = r'C:\Program Files\Mozilla
Firefox'
shortcut.save()



This creates the following target path (which doesn't work for 
obvious reasons) in the shortcut's Target Path. The extra "C:\" is 
getting in there somehow...


"C:\"C:\Program Files\Mozilla Firefox\firefox.exe" https:
\www.myCompanyWebsite.com\ 
auth\preauth.php"


If I leave the website off the TargetPath, it works. If I take the 
path to Firefox
out of the TargetPath, it works too. Is there another method I can 
use other than

creating the shortcut by hand and using the shutil module?

Thank you for any ideas.

Mike


I think you need to put the URL in shortcut.Arguments rather than
appending it to the executable path.

 Roger





Someone on c.l.py pointed this out too. I was unaware that that existed. 
It works great though. Thanks a lot!


Mike
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem creating a shortcut

2008-05-16 Thread Mike Driscoll

Tim,
Mike 
Driscoll wrote:


I've had this niggling issue from time to time. I want to create a
shortcut on the user's desktop to a website that specifically loads
Firefox even if Firefox is not the default browser.
...
shortcut = shell.CreateShortCut(userDesktop + '\\MyShortcut.lnk')
shortcut.Targetpath = r'"C:\Program Files\Mozilla Firefox\firefox.exe"
https:\www.myCompanyWebsite.com\ 
auth\preauth.php'

shortcut.WorkingDirectory = r'C:\Program Files\Mozilla
Firefox'
shortcut.save()




Do you understand that it is not safe to assume that Firefox lives in 
"C:\Program Files\Mozilla Firefox"?  I often override my application 
install directories to keep the paths short, so I put it in 
"C:\Apps\Firefox".  Plus, the "Program Files" path name is localized 
on the international versions of Windows.


I guess I should have described my environment a little more. This is 
for a logon script at a business. The user's have no control over where 
Firefox resides and if they happen to uninstall it or do not have it in 
the first place, one of my other scripts will install it for them in the 
background.


The reason is quite simple. We use Zimbra which runs much better in 
Firefox than any other browser we've tested. But you and the others are 
correct. If this had been an application, then I wouldn't have done this 
the way that I am.




You'll need to dig in the registry, in 
HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox.  Fetch the 
"CurrentVersion" string value, then look inside that key, in Main, and 
fetch the PathToExe string.  Something like this:


ffkey = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, 
'SOFTWARE\\Mozilla\\Mozilla Firefox')

ffver = _winreg.QueryValueEx( ffkey, 'CurrentVersion' )[0]
print ffver
ffmainkey = _winreg.OpenKey( ffkey, sub + "\\Main" )
ffpath = _winreg.QueryValueEx( ffmainkey, 'PathToExe' )[0]
_winreg.CloseKey( ffkey )
_winreg.CloseKey( ffmainkey )



Thanks for the advice,

Mike
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Attaching Menu to Any App

2008-05-16 Thread Larry Bates

Tim Golden wrote:

Tim Roberts wrote:
What *I* said was that it could NOT be done in pure Python, but I was 
expecting Mark Hammond or Tim Golden to contradict me in such a 
pessimistic statement.  ;)


I was trying to hold back from a tirade of pointing
out how foolish an idea this was. Why is it that people
(a) want to to do intrusive things with other people's
interfaces? and (b) want it to be easy and risk-free?

(sigh)

Tim


While I agree with Tim that unilaterally trying to add something to another 
applications menu will be a lesson in futility, many Windows applications have 
clearly defined APIs for adding items to their menus or toolbars (Microsoft 
Office, etc).  A good place to start would be to look at Mark Hammond's 
excellent SpamBayes plug-in for Outlook on how to add utilities to such 
applications.


-Larry

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Volume Serial Number

2008-05-16 Thread Rickey, Kyle W
How do I get the volume serial number for a drive? For example in the
cmd prompt issuing this:

 

C:\>vol C:

 Volume in drive C is LABEL

 Volume Serial Number is -

 

Is the volume serial number wrapped by pywin32? I found the function
win32api.GetVolumeInformation, but it doesn't seem to return what I
want.

 

-Kyle Rickey

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Dahlstrom, Roger
only way I know how to do it is 
 
import os
out = os.popen("dir SomethingThatDoesntExist")
print out



From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rickey, Kyle W
Sent: Friday, May 16, 2008 11:36 AM
To: python-win32@python.org
Subject: [python-win32] Volume Serial Number



How do I get the volume serial number for a drive? For example in the cmd 
prompt issuing this:

 

C:\>vol C:

 Volume in drive C is LABEL

 Volume Serial Number is -

 

Is the volume serial number wrapped by pywin32? I found the function 
win32api.GetVolumeInformation, but it doesn't seem to return what I want.

 

-Kyle Rickey



DISCLAIMER:
This e-mail, and any attachments thereto, is intended only for use by the 
addressee(s) named herein and
may contain legally privileged and/or confidential information. If you are not 
the intended recipient
of this e-mail, you are hereby notified that any dissemination, distribution or 
copying of this e-mail, and 
any attachments thereto, is strictly prohibited. If you have received this in 
error, please immediately notify 
me and permanently delete the original and any copy of any e-mail and any 
printout thereof. 
E-mail transmission cannot be guaranteed to be secure or error-free. The sender 
therefore does not accept 
liability for any errors or omissions in the contents of this message which 
arise as a result of e-mail transmission.

NOTICE REGARDING PRIVACY AND CONFIDENTIALITY
Direct Edge ECN LLC may, at its discretion, monitor and review the content of 
all e-mail communications.

www.directedge.com
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tim Roberts

Dahlstrom, Roger wrote:

only way I know how to do it is
 
import os

out = os.popen("dir SomethingThatDoesntExist")
print out


The "vol" command was designed for this purpose:
   out = os.popen("vol")

although GetVolumeInformation is a better way.

--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tony Cappellini
That's not the serial number of the drive- as assigned by the drive
manufacturer.

If you want the SN from the drive manufacturer, you will need to issue an
IOCTL ATA Passthrough command which sends the  ATA Identify Device command
to the drive. Unless the Winapi has a wrapper for that functionality, you
can't do that via Python.

You would have to install the Windows SDK to compile a tiny program to issue
the Identify Device command and pull out the SN from the data coming back,
which is only 512 bytes.

This would have to be written in C. It's not difficult to do and the program
would only require less than100 lines of C code.
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tim Roberts

Rickey, Kyle W wrote:


How do I get the volume serial number for a drive? For example in the 
cmd prompt issuing this:


 


C:\>vol C:

 Volume in drive C is LABEL

 Volume Serial Number is -

 

Is the volume serial number wrapped by pywin32? I found the function 
win32api.GetVolumeInformation, but it doesn’t seem to return what I want.




Yes, actually, it does.  The second item in the tuple it returns is the 
VSN as a 32-bit binary value.


You were probably confused because Python showed it to you as a signed 
decimal integer.  If your VSN is really -, then it probably 
showed you -65535.  If you print that in hex, you get -, and if you 
treat that as unsigned, you get .


I wish I knew a better way to do the signed/unsigned mangling, but try this:

   def UnsignedHex( v ):
   if v >= 0: return '%08X' % v
   return '%08X' % (0x1 + v )
   print UnsignedHex( win32api.GetVolumeInformation('C:\\')[1] )

--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tony Cappellini
Message: 5
> Date: Fri, 16 May 2008 10:35:45 -0500
> From: "Rickey, Kyle W" <[EMAIL PROTECTED]>
> Subject: [python-win32] Volume Serial Number
> To: 
> Message-ID:
><[EMAIL PROTECTED]
> >
> Content-Type: text/plain; charset="us-ascii"
>
> >>How do I get the volume serial number for a drive? For example in the
> >>cmd prompt issuing this:
>
> It looks like Tim Golden has a way to do what you want- via Python!
http://tgolden.sc.sabren.com/python/win32_how_do_i/see_if_two_files_are_the_same_file.html
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] [OT] Anyone happen to know the system-wide limit of HANDLEs in Windows 2000 Server?

2008-05-16 Thread Tim Roberts

Trent Nelson wrote:

I'm debugging a weird/sporadic COM/ActiveX error with an application on a 
client's site that's recently been 'migrated' to Citrix Metaframe on Windows 
2000 Server.  I'm starting to think we may be hitting the system-wide limit for 
how many HANDLEs can be created across all processes every so often, which 
always causes weird and wonderful behaviour.

However, I can't remember what the system-wide limit is, and stfw'ing didn't 
turn up any clues.  I recall reading something in a GDI programming book 
recently where the author used brute force to demonstrate that the system limit 
was around X handles -- but I can't remember what X was, I think it was around 
43,000, but I'm not sure.

Anyone here happen to know off the top of their head?
  


10,000 per process.   32,700 system-wide.  That's window manager objects 
-- window handles.  GDI object handles are separate.


http://blogs.msdn.com/oldnewthing/archive/2007/07/18/3926581.aspx
http://msdn.microsoft.com/en-us/library/ms725486.aspx
http://msdn.microsoft.com/en-us/library/ms724291.aspx

--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tim Roberts

Tony Cappellini wrote:


>>How do I get the volume serial number for a drive? For example
in the
>>cmd prompt issuing this:

It looks like Tim Golden has a way to do what you want- via Python!
http://tgolden.sc.sabren.com/python/win32_how_do_i/see_if_two_files_are_the_same_file.html


Tim Golden has a way to do just about everything, but this particular 
snippet has nothing to do with the original question.


--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem creating a shortcut

2008-05-16 Thread Mike Driscoll

Tim Golden wrote:
Sorry, 
missed this one going through. Looks like

Roger's hit the nail on the head, though. Bizarre
behaviour by the IShellLink interface: I can't find
any kind of reference to this but I assume that
since the Path attribute of the link should *only*
contain an executable, there's no need for the
quotes -- which then confuse it when they're there
as it tries to make the executable into an absolute
path.

One small comment, Mike. Since you're using the
winshell module -- which I assume is the one from
my site -- why not use its CreateShortcut function?
It's basically just a light wrapper around the IShellLink
functionality which someone else mentioned:


import os, sys
import winshell

winshell.CreateShortcut (
Path=os.path.join (winshell.desktop (), "shortcut.lnk"),
Target=r"c:\Program Files\Mozilla Firefox\firefox.exe",
Arguments="http://localhost";,
Description="Open http://localhost with Firefox"
)



But maybe you're using the WScript.Shell functionality
elsewhere as well?

TJG





Good point. I am using your module (thanks!). Somehow I missed it's 
shortcut creating abilities. I do use the WScript.Shell earlier in my 
script, but I think it's just for other types of shortcut creation.


I'll have to look. It would be good not to have to import extra stuff.

Mike

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tim Golden

Rickey, Kyle W wrote:
How do I get the volume serial number for a drive? For example in the 
cmd prompt issuing this:


WMI to the rescue?


import wmi

for volume in wmi.WMI ().Win32_LogicalDisk ():
  print volume.Caption, "=>", volume.VolumeSerialNumber



TJG
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number [SOLVED]

2008-05-16 Thread Rickey, Kyle W
Thanks to all for your responses.

I tried both methods from each Tim. :)

> Yes, actually, it does.  The second item in the tuple it returns is
the
> VSN as a 32-bit binary value.

Ahh, now I understand where I messed up, your code example enlightened
me.

> WMI to the rescue?
> 
> import wmi
>
> for volume in wmi.WMI ().Win32_LogicalDisk ():
>print volume.Caption, "=>", volume.VolumeSerialNumber
>
> 

This example also worked quite well. In addition to that there's lots of
juicy information available from the 'volume' object. Thanks for that!

> If you want the SN from the drive manufacturer, you will need to issue
an > IOCTL ATA Passthrough command which sends the  ATA Identify Device
command > to the drive. Unless the Winapi has a wrapper for that
functionality, you > can't do that via Python.

Thanks for that as well, although not what I was looking for, I'll save
that for a rainy day. :)

Just for message consistency, I've reposted Tim Robert's example below:

def UnsignedHex( v ):
if v >= 0: return '%08X' % v
return '%08X' % (0x1 + v )
print UnsignedHex( win32api.GetVolumeInformation('C:\\')[1] )

Thanks again to everyone for your help.

-Kyle Rickey
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tim Golden
Sent: Friday, May 16, 2008 12:45 PM
Cc: python-win32@python.org
Subject: Re: [python-win32] Volume Serial Number

Rickey, Kyle W wrote:
> How do I get the volume serial number for a drive? For example in the 
> cmd prompt issuing this:

WMI to the rescue?


import wmi

for volume in wmi.WMI ().Win32_LogicalDisk ():
   print volume.Caption, "=>", volume.VolumeSerialNumber



TJG
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Is WMI ever disabled?

2008-05-16 Thread python
I've been enjoying a lot of the WMI examples posted on this mailing
list.

Does anyone know if WMI is ever fully or partially disabled by corporate
customers, eg. as a way to secure workstations?

I'm trying to figure out how confident one can be about assuming WMI
functionality will be available on real-world 'locked-down' corporate
workstations.

Thank you,
Malcolm
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tony Cappellini
>>Tim Golden has a way to do just about everything, but this particular
>>snippet has nothing to do with the original question.

def get_unique_id (hFile):
  (
attributes,
created_at, accessed_at, written_at,
volume,
file_hi, file_lo,
n_links,
index_hi, index_lo
  ) = win32file.GetFileInformationByHandle (hFile)
  return volume, index_hi, index_lo


The link I posted certainly has a misleading name, but the code above
(from that link) returns the volume SN.
Is the fifth item returned from
GetFileInformationByHandle() not the Volume SN?

[0] *int* : dwFileAttributes
[1] *PyTime * : ftCreationTime
[2] *PyTime * : ftLastAccessTime
[3] *PyTime * : ftLastWriteTime
[4] *int* : dwVolumeSerialNumber
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Volume Serial Number

2008-05-16 Thread Tim Roberts

Tony Cappellini wrote:

>>Tim Golden has a way to do just about everything, but this particular
>>snippet has nothing to do with the original question.

def get_unique_id (hFile):
  (
attributes,

created_at, accessed_at, written_at,
volume,
file_hi, file_lo,
n_links,
index_hi, index_lo
  ) = win32file.GetFileInformationByHandle (hFile)
  return volume, index_hi, index_lo

The link I posted certainly has a misleading name, but the code above (from 
that link) returns the volume SN.
Is the fifth item returned from GetFileInformationByHandle() not the Volume SN? 
  


You are quite correct, I apologize.

--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Is WMI ever disabled?

2008-05-16 Thread Tim Roberts

[EMAIL PROTECTED] wrote:

I've been enjoying a lot of the WMI examples posted on this mailing
list.

Does anyone know if WMI is ever fully or partially disabled by corporate
customers, eg. as a way to secure workstations?
  


I would expect quite the opposite.  In corporate situations, WMI is 
often exploited quite heavily for monitoring, logging, and administration.


--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Is WMI ever disabled?

2008-05-16 Thread Tim Golden

[EMAIL PROTECTED] wrote:

I've been enjoying a lot of the WMI examples posted on this mailing
list.

Does anyone know if WMI is ever fully or partially disabled by corporate
customers, eg. as a way to secure workstations?

I'm trying to figure out how confident one can be about assuming WMI
functionality will be available on real-world 'locked-down' corporate
workstations.


Interesting because of course WMI can be used to do so many
things remotely that it might be considered a security risk.
You can secure it down to namespace level but no lower than
that, I think: if a user has access to, say, view Volume labels,
then they can create new processes (altho' there are privilege
implications on some such things).

In short, though, I've never heard of an environment where it
is disabled since its potential for remote administration and
so on is so useful.

TJG
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32