Page 2 of 2 <12
Topic Options
#179460 - 2007-08-17 11:58 PM Re: Script Request [Re: Templar]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You can always navigate to wellknown places in the workbook, like the first empty cell in column A. The macro recorder is very helpfull in revealing the code
;Script Options
If Not @LOGONMODE
    Break On
Else
    Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
If @SCRIPTEXE = "KIX32.EXE"
    $RC = SetOption("WrapAtEOL", "On")
EndIf

;Declare variables
DIM
 
$objExcel

;Initialize variables
;Create the Excel object, check if succeeded, else quit

$objExcel = CreateObject("Excel.Application")
If @ERROR
    Exit @ERROR
EndIf

;Code
;Show Excel

$objExcel.Visible = -1
;Open workbook with read-only password
$RC = $objExcel.Workbooks.Open("C:\test\Book1.xls",,,,"test")
;Goto cell A1 (Ctrl-Home)
$RC = $objExcel.Range("A1").Select
;Goto first empty cell (End, Arrow Down)
$RC = $objExcel.Selection.End(xlDown).Select
;Get $RC

Top
#179461 - 2007-08-18 01:11 AM Re: Script Request [Re: Witto]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ah ok - I see that password now. I was looking in "Protection" and "Protect Sheet" and "Protect Workbook", not in Options ... anyways, here's a modified script for that password protection ...

 Code:
Break On

$= SetOption("WrapAtEol", "On")

$= SetExcelValue("c:\sheet.xls", "tuesday", "B5", "123", "abc123")

? @SERROR

Exit 1

Function SetExcelValue($path, $sheet, $range, $value, $password)

 Dim $Excel
 Dim $WorkBook
 Dim $WorkSheet

 $Excel = CreateObject("Excel.Application")

 If @ERROR = 0
 
  $Excel.DisplayAlerts = 0

  $WorkBook = $Excel.WorkBooks.Open($path,,,,$password)

  If @ERROR = 0

   $WorkSheet = $WorkBook.Sheets.Item($sheet)

   If @ERROR = 0

    $WorkSheet.Range($range).Value = $value

    $= $WorkBook.Save()

    $WorkSheet = 0

   Endif

   $WorkBook = 0

  Endif

  $Excel.Quit
  $Excel = 0

 Endif

 Exit @ERROR

EndFunction

Top
#179466 - 2007-08-19 02:18 PM Re: Script Request [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
 Originally Posted By: NTDOC
Using UPTIME from Microsoft you can do UPTIME /S and it will give you a log of all up and down time and length and average, etc..

Just be aware that the MS Uptime tool requires admin access to provide accurate info. It will usually display something whether you have admin access or not.. the problem is that the info presented without admin rights is based on the oldest event log entry, which will be wildly inaccurate if you regularly clear event logs.

At my prior employer, the event logs are dumped/cleared nightly. The members of the operations team did not have admin rights with their normal login, and the uptime checked (via UPTIME \\SERVER) at 4am would show only 4 hours or less of uptime. In fact, if no events occurred between midnight and, say, 3:15, it would show only 45 minutes of uptime! They would call the on-call person to report an unexpected reboot. We'd check and see 3 weeks, and think they were halucinating.

Just something to keep in mind with this tool.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#179467 - 2007-08-19 09:04 PM Re: Script Request [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well I would hope that your experience is not the norm in most shops. And as for Admin rights well pretty much any remote tool requires Admin rights as well.

But true what you say if someone is managing logs like that.

Top
#179469 - 2007-08-19 11:32 PM Re: Script Request [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
so, the tool actually does not work at all if it only relies on eventlog.
_________________________
!

download KiXnet

Top
#179470 - 2007-08-20 01:03 AM Re: Script Request [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
If you're trying to be "scientific" and must know to the Nth degree then perhaps not.

Luckily perhaps for me I've never had to work in such an environment as that and the tool works just fine for me. I'm not trying to do forensic analysis of how long a system has been up too often or what it's pattern of up / down time is (Microsoft monthly updates has but a squash on stuff like that)

I'm not trying to convince anyone to move over to this tool. If you like or want to do it any other way be my guest. Just mentioning it's out there and works fine (in a normal business that has to spend time and money on things a bit more important than the up/down patterns of a Server or Workstation) I agree that it is NOT a tool to use if those items are that important to you.

Top
#179474 - 2007-08-20 01:40 PM Re: Script Request [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
er - no.. that's not the issue..

The Ops staff had admin rights with an alternate account. If you log in with admin rights, the uptime tool uses the registry to find the boot time and such similar records. Accurate enough, but if you are not an admin - as the Ops team was when they were logged into their workstations - the tool "appears" to work, and does so by looking for the boot record in the event log. Not finding the boot record, it takes the "oldest" record in the log as the boot time. I guess the team the wrote the tool never had to dump and archive their event logs!

Doc - if my staff was using admin accounts for normal logins, I'd have a real issue with that! The problem with the tool is that it appears to respond normally, except for a short message at the end - not where you'd be focusing your attention when doing an uptime check. You need to either use RunAs, or log directly into the server with your admin account to get accurate data.

Just something to be aware of if you choose to use this tool, that's all. For the record, I use this tool extensively, but only when I'm logged in as an admin.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#179478 - 2007-08-20 06:52 PM Re: Script Request [Re: Glenn Barnas]
Templar Offline
Fresh Scripter

Registered: 2002-04-11
Posts: 41
Loc: Cincinnati
I tried the last code adn it still does not enter in the password when the prompt comes up.
It does update the file when I enter in the password.
How does Excel get a password passed to it?

Top
#179479 - 2007-08-20 08:23 PM Re: Script Request [Re: Templar]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I dont know - works for me. If I manually start the spread-sheet I get a little tiny dialog box (like this) asking me for the password:

 Code:
--------------------------
'sheet.xls' is protected

Password: [             ]
--------------------------


If I run the script above and change $password to be the correct password - no prompt and the spreadsheet just updates itself.

Can anybody else try (make sure to have a sheet called "Tuesday" in your workbook and set the password from Tools->Options.


Top
#179480 - 2007-08-20 09:06 PM Re: Script Request [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Quote:

....
Can anybody else try
....


Just did and it works fine for me. WinXP pro SP2 and Excel 2K3 build 11.5612.5606.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179482 - 2007-08-20 09:33 PM Re: Script Request [Re: Shawn]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Shawn,

Question

Why do you do exit 1 at the end? This will always set @error to 1 right even if the script finished without errors or am I missing something?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#179483 - 2007-08-20 10:10 PM Re: Script Request [Re: Mart]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Its an old-old habit. I mostly do Exit 0 at the end of scripts - Richard got me into that habit. But my reasoning before what that 1 = TRUE and 0 = FALSE and script returns TRUE. Odd I know - dont do it much anymore unless I just forget.
Top
Page 2 of 2 <12


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.036 seconds in which 0.014 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org