Jump to content
Software FX Community

MarcoS

Members
  • Content Count

    6
  • Joined

  • Last visited

Everything posted by MarcoS

  1. I saw a posting last week in the forums HERE. The poster is looking to find out if they can plan sounds in a gadget when the data or value changes. One thing to remember when dealing with gadgets, and their refresh option, is that you
  2. Try using scriptblocks to load the values: http://community.softwarefx.com/blogs/powergadgets_team_blog/archive/2007/02/23/Connecting-to-CSV-data-from-PowerGadgets.aspx In the end, having the quotes around the numerical values, could cause an issue at first glance. You want strings to simply be VALUE, yet numerical values to be represented as "NUMBER". The simple fact that you're quoting the numerical values would have led me to think PowerShell/PowerGadgets would have forced this to be recongnized as a string, but I guess I'm wrong. WorkOnChartPrint.zip
  3. Something that has come up quite a bit is people asking how they can possibly hide senstive information in their PowerGadgets files. When you use the PowerGadgets Creator, your gadget is saved in a .pgf file extension which is basically XML formatted data. Here's an example where I've extracted one particular section of the .pgf XML: <Window> <GadgetVersion>1</GadgetVersion> <ValueFieldCount>1</ValueFieldCount> <ValueField0>Latitude</ValueField0> <Data>PowerGadgets.Commands.PowershellSource</Data> <Data.PrevCommands>invoke-webservice -wsdl "http://www.webservicex.net/WeatherForecast.asmx?WSDL" -method "GetWeatherByZipCode" "80526"</Data.PrevCommands> </Window> (Yes, I'm calling the invoke-webservice cmdlet directly. I could have produced different code depending on the options I chose in the Creator wizard.) OK, in some situations, the gadget creator may have senstive information they may want to somewhat hide. At least have the text scrambled somewhat so a regular user can't easily view the information in a text editor. The PowerGadgets Quick Start Guide has information in digitally signing the .pgf files, but that only provides protection against tampering of the .pgf file. The information, such as the command run, is not scrambled in any way. For Windows PowerShell version 1.0: Using this specific example, I wrote up a blog post HERE on how one can use some programming in C# to hide the invokation details. Now, you might be able to just plugin your own details and follow the steps to the letter, but if you have more than one parameter, then that will change some of the C# programming as well. Just post in the forums if you need any help compiling your own custom code. For Windows PowerShell version 2 CTP: (The above method for version 1.0 can also be used with the version 2 CTP.) In November 2007, the Windows PowerShell team released a Community Technology Preview of the next release of Windows PowerShell. This early release provides something new called scriptcmdlets. Basically, it is as if you can create your own cmdlets simply by creating PowerShell scripts. Once the scriptcmdlet is loaded, it acts just like a real cmdlet (with some minor exceptions). Scriptcmdlets alone, still doesn't resolve our problem, because to load the scriptcmdlet, you load a plain .ps1 script which is in plain text. However, there is a product named PowerLocker which comes to the rescue. PowerLocker can encrypt PowerShell scripts. It does need to be loaded on all machines that may try to run encrypted scripts, but it comes in two versions: a commercial version (can lock/unlock any script), and a free/community version (can lock scripts up to 20 lines/unlock any script). With the help of PowerLocker, you know have a script that can be passed around, either loaded manually or via the user's profile, and then once has that cmdlet available to use. See my detailed example HERE. There are some other for hiding information. The important thing I was looking for in encrypting/hiding my parameters was that I wanted the result to ouput real .NET objects. That's the important part to consider here. Other methods that I tried would simply output simple text strings, which may be acceptable in some cases. I may blog about these other methods briefly early in 2008.
  4. A lesser known cmdlet is get-credential, which allows one to create a credential object containing a username and password. A lot of cmdlets, that might somehow require some kind of authentication, support the credential parameter, which will use this credential object. Some examples of cmdlets that support the credential parameter are invoke-sql and invoke-webservice. One way of using the credential object is to do something like this: PSH>$cred=get-credential A window will popup asking for your username and password. Once you have the $cred variable, you would use it like this to call one of the invoke cmdlets: PSH>invoke-webservice -credential $cred ... or PSH>invoke-sql -credential $cred ... This allows you to use services that require authentication. You can also use this method to store a username and password to a file for later use when invoking the cmdlet again. In other words, you could create a credential object, store that in a file, and later retrieve it. I'll blog about how one can do that at a later time along with the pros and cons of that method. [Edit: October 3rd, 2007: It is possible to block the Windows popup, and enter your username and password directly into PowerShell. Oisin Grehan posted a quick command in the PowerShell NNTP group that you can run to set this up: new-itemproperty hklm:\software\microsoft\powershell\1\shellids -name consoleprompting -propertytype string -value true]
  5. Last week, I blogged about creating a stock ticker with out-gauge. This week, I'm going to do a flashing display. My script will open up a digital type gadget, text will basically flash for about 5 seconds, then remain constantly on the screen. --------------start flash.ps1--------------- #We change the $erroractionpreference here. If this is the first time this runs, when the new runspace is invoked, an error could occur. #This may not be the best solution... $erroractionpreference="silentlycontinue" #We create a function to determine if the current tick value is even or odd. This is how we determine what phase of the flash we are in: #do we show the string or hide it this run. function check-even ($num) {[bool]!($num%2)} #Check if tick had already been defined in the current runspace. $check=get-variable tick -scope global #We setup a global variable here. Global because we are going to use the -refresh parameter #and need the variable to be available in the new PowerShell runspace created. if (($check -eq $null)) {$global:tick=0} #As long as tick is less than 6, in this case, we still want to flash the string. Once we reach 6, #the string is shown indefinitely. if ($global:tick -lt 6) { if (check-even $global:tick) {$value="test"} else {$value=""} } else { $value="test" } #Increment tick for the next run. $global:tick++ #Echo the current string to pass off to out-gauge. $value --------------stop flash.ps1--------------- So once you have the script saved, you can call it like so: PSH>./flash.ps1|out-gauge -type digital -refresh 0:0:01 -floating -topmost I still have to blog about the traffic light, and that should be next week. I am also planning to tie together the stock ticker, flash, and the drilldown feature in a future blog post.
  6. One thing I asked for recently on the community forums was a stock ticker gadget. It just sounded like something interesting to have in my toolbox. After some thought after a recent long flight, I thought of an easy way this could be done. I just needed to create a string of text, and figure out how to make it appear to move. One easy way was using the Substring() method of the System.String class. The code is pretty easy once you think about it, which you should be able to just copy and paste into your favorite PowerShell editor (mine is Notepad): ---------start scroll.ps1--------- #We setup a global variable here. Global because we are going to use the -refresh parameter #and need the variable to be available in the new PowerShell runspace created. #The value is 7 in this case simply because this is how many characters we want to see on the #screen in this case. $global:scrollValue=7 #To save some typing, we create a couple of local variables also. $spacer=" "*7 $string="this is a test of powergadgets" #We create are complete string. The "spacer" is used so the text appears to start from #nowhere after a short pause. $scrollString=$spacer+$string+$spacer #Here we get the section of string that we want to show on the screen during the current iteration. $scrollText=$scrollString.Substring($global:scroll_iteration,$global:scrollValue) #On each run, we increment the global iteration variable so we move along the string. #We also reset the global iteration value to zero, so the scroll goes on indefinitely. if ($global:scroll_iteration -lt $scrollString.length-$global:scrollValue) { $global:scroll_iteration++ } else { $global:scroll_iteration=0 } #The final text outputted. $scrollText ---------stop scroll.ps1--------- So once you have the script saved, you can call it like so: PSH>./scroll.ps1|out-gauge -type digital -refresh 0:0:01 -floating -topmost Note, if you see some text appear, then it appears the gadget resets itself, and then seems to run OK, the script sets some global variables, and that will affect anything using those particular variables in any scope in your current PowerShell session. You may need to do something like this in your PowerShell session to reset the global variables: PSH>$scroll_iteration=0;$scrollValue=0 I hope you like this little addition. I will be blogging about a traffic light I created soon. [Edit: September 14th, 2007, by Marco Shaw: See this forum thread for more information on different things that can be done with the stock ticker. There's also a "version 2" posted there.]
×
×
  • Create New...