in reply to Re: VSS automation strange problem
in thread VSS automation strange problem

I think you are right. I have been running the script via Komodo IDE so I can debug it. I did not configure it as a separate user, but when I run
#!/usr/bin/perl -w use strict; my $foo = `echo %SSDIR%`; print $foo;
from it, it shows that the ENV variable is not set, whereas it is from the command line.

But there is only one user on this (Windows 10) machine. Any idea how to track down what user Komodo is running under?

"I think computers have complicated lives very bigly. The whole age of, you know, computer has made it where nobody knows exactly what's going on." --D. Trump

Replies are listed 'Best First'.
Re^3: VSS automation strange problem
by huck (Prior) on Jan 04, 2017 at 01:24 UTC

    one end user maybe, but many other "users" too. SYSTEM, NETWORK SERVICE, LOCAL SERVICE are but a few others. Maybe this will help, i use it to identify who runs my code from a console

    use Win32; my $user = Win32::LoginName();
    If you can put your process into sleep for a bit and can identify it from this list this may help
    use strict; use warnings; use DBI; use DBD::WMI qw/connect prepare execute fetchrow/; use Win32::OLE qw/in/; # needs DBD::WMI # http://search.cpan.org/~corion/DBD-WMI-0.07/lib/DBD/WMI.pm # corion@cpan.org http://www.perlmonks.org/?node_id=5348 # http://www.perlmonks.org/?node_id=565819 #clues from # http://www.perlmonks.org/?node_id=821593 # https://gist.github.com/aero/1260973/6efbe8684aa54c8aecb73f601e511a5 +3bfb5c6b1 # https://msdn.microsoft.com/en-us/library/aa394388(v=vs.85).aspx # https://msdn.microsoft.com/en-us/library/aa394084(v=vs.85).aspx my $dbh = DBI->connect('dbi:WMI:'); sub do_table{ my @tables=@_; table: for my $table (@tables){ my $sth = $dbh->prepare('SELECT * FROM '.$table); unless ($sth->execute()) { print 'Unable to select from:'.$table." +\n"; next table;} print 'Table:'.$table."\n"; my $rowct=0; while (my( $row ) = $sth->fetchrow) { print ' row:'.$rowct++."\n"; foreach my $object ( in($row->{Properties_}) ) { my $outline=" $object->{Name} = "; if ( ref($object->{Value}) eq "ARRAY") { $outline.="{ "; foreach my $value ( in($object->{Value}) ) {$outline.="$va +lue ";} $outline.="}"; } else { $outline.=($object->{Value} // ""); } print $outline."\n"; } # $object } # thing } # table } # do_table do_table("Win32_Process");

      While win32_process is cute, it doesnt seem to reply with the username like i thought it did. try this instead

      tasklist /v

        Hey i fixed it, well after fighting through a problem

        Win32::OLE(0.1712) error 0x80010105: "The server threw an exception" in METHOD/PROPERTYGET "GetOwner" at wmi-dbi.pl line 65.
        seems GetOwner wont work on certain rows, so they dont return a user line

        This is the same as above with the addition of the sub owner_method and its call, i wasnt sure what to say to fix the above post ...

        use strict; use warnings; use DBI; use DBD::WMI qw/connect prepare execute fetchrow/; use Win32::OLE qw/in/; #http://stackoverflow.com/questions/14257565/how-to-find-a-process-of- +the-current-user-in-perl-using-wmi # needs DBD::WMI # http://search.cpan.org/~corion/DBD-WMI-0.07/lib/DBD/WMI.pm # corion@cpan.org http://www.perlmonks.org/?node_id=5348 # http://www.perlmonks.org/?node_id=565819 #clues from # http://www.perlmonks.org/?node_id=821593 # https://gist.github.com/aero/1260973/6efbe8684aa54c8aecb73f601e511a5 +3bfb5c6b1 # https://msdn.microsoft.com/en-us/library/aa394388(v=vs.85).aspx # https://msdn.microsoft.com/en-us/library/aa394084(v=vs.85).aspx my $dbh = DBI->connect('dbi:WMI:'); sub do_table{ my @tables=@_; table: for my $table (@tables){ my $sth = $dbh->prepare('SELECT * FROM '.$table); # Win32_SerialPo +rt unless ($sth->execute()) { print 'Unable to select from:'.$table." +\n"; next table;} print 'Table:'.$table."\n"; my $rowct=0; while (my( $row ) = $sth->fetchrow) { print ' row:'.$rowct++."\n"; foreach my $object ( in($row->{Properties_}) ) { my $outline=" $object->{Name} = "; if ( ref($object->{Value}) eq "ARRAY") { $outline.="{ "; foreach my $value ( in($object->{Value}) ) {$outline.="$va +lue ";} $outline.="}"; } else { $outline.=($object->{Value} // ""); } print $outline."\n"; } # $object owner_method($row); } # thing } # table } # do_table do_table("Win32_Process"); exit; sub owner_method { #http://stackoverflow.com/questions/14257565/how-to-find-a-proce +ss-of-the-current-user-in-perl-using-wmi use Win32::OLE::Variant; my $row=shift; ### important getowner can return an fatal error otherwise local $Win32::OLE::Warn=0; ### important getowner can return an fatal error otherwise foreach my $object ( in($row->{Methods_}) ) { if ($object->{Name} eq 'GetOwner') { my $useridval; my ($strUser, $strDomain) = ( Variant(VT_BSTR|VT_BYREF, +''), Variant(VT_BSTR|VT_BYREF, '') ); my $name=$object->{Name}; $useridval = $row->GetOwner($strUser, $strDomain); if (defined($useridval) && length($useridval) > 0) { if ($useridval == 0 ){ print ' GetOwner->User = ' . $strDomain->Value.'\ +\'.$strUser->Value . "\n"; } } } } # method } # owner_method do_table("Win32_LogonSession"); do_table("Win32_Useraccount"); #do_table("Win32_SessionDirectorySession"); #do_table("Win32_SessionDirectorySessionEx"); do_table("Win32_ComputerSystem"); do_table("Win32_Process"); do_table("Win32_OperatingSystem"); do_table("Win32_ComputerSystem"); do_table("Win32_DiskPartition"); do_table("Win32_Property"); do_table("Win32_POTSModem"); do_table("Win32_SystemBIOS"); do_table("Win32_MemoryArray"); do_table("Win32_DeviceSettings"); do_table("Win32_LogicalDisk"); do_table("Win32_PhysicalMedia"); do_table("Win32_Account"); do_table("Win32_Perf WHERE Name = 'PERL'"); do_table("Win32_NetworkAdapter"); do_table("Win32_Perf"); do_table('Win32_SerialPort'); do_table("Win32_Win32_NetworkConnection WHERE ConnectionState != 'Conn +ected'"); do_table(qw/Win32_SerialPort Win32_TemperatureInfo Win32_LogonSession Win32_NetworkAdapterConfiguration Win32_Win32_NetworkConnection Win32_Processor Win32_Fan Win32_BaseBoard Win32_BIOS Win32_Bus Win32_DesktopMonitor Win32_Desktop Win32_Share /);
        Can you tell ive been having some fun with corion's module?

Re^3: VSS automation strange problem
by huck (Prior) on Jan 04, 2017 at 06:59 UTC

    Answering your question is one thing, but this may solve your initial problem better. add this to your code before my $result=...

    $ENV{SSDIR}='c:\\some\\path\\to\\some.ini';
    And if you didnt restart your IDE after setting SSDIR outside it by hand that may be what the problem is. And if you set it via a more permanent method you may need to logoff/login again.

      When I run this from Komodo
      #!/usr/bin/perl -w use strict; use Win32; my $user = Win32::LoginName(); print "$user\n\n"; my $tasklist = `tasklist /v`; print $tasklist; chdir('C:\Program Files (x86)\Microsoft Visual SourceSafe'); $ENV{SSDIR} = 'C:\Program Files (x86)\Microsoft Visual SourceSafe'; my $env = `echo %SSDIR%`; print "\n$env\n"; my $result = `SS Dir \"$/\" -Yadmin`; print $result;
      I get the one user (me) on the system, perl.exe has the same user, it echoes the correct SSDIR, then I get the error about the SSDIR variable not being set. When I run echo %USERDOMAIN%\%USERNAME% from the command window I get the same user as the script. Also when I drop the script into the VSS directory and run it from the command line I get the same result, running either in a plain command window or and administrator command window. So I guess it's not a Komodo issue.

      How strange.

      "I think computers have complicated lives very bigly. The whole age of, you know, computer has made it where nobody knows exactly what's going on." --D. Trump

        Are you really, really sure that you want to run the following command:

        `SS Dir \"$/\" -Yadmin`

        Printing out the string that Perl (and the shell) would try to run shows me:

        SS Dir " " -Yadmin

        ... which most likely is not what you intended it to be. At least, I am unaware of Windows programs that handle newlines in their argument line well, if the shell even passes them through.

        What did you expect "$/" to do?