• Use Open AI to write code for you?

    Home » Forums » Outside the box » Learn to code » Use Open AI to write code for you?

    Author
    Topic
    #2506015

    I saw a story on Life Hacker about the Free Open AI and thought I’d give it a try and see if I could cause it problems, but much to my suprise!

    I asked: Write a Powershell program to change a userid

    It responded:

    To change a userid in Powershell, you can use the Set-LocalUser cmdlet. This cmdlet allows you to modify the properties of a local user account, including the userid.
    
    Here is an example of how to use this cmdlet to change a user's userid:
    

    OpenAI1

    This code first gets the user account with the name "username" and then uses the Set-LocalUser cmdlet to change the userid of that account to "newusername".
    
    Remember to replace "username" and "newusername" with the actual userid and the new userid that you want to use.
    
    You can also use the Get-LocalUser cmdlet to verify that the userid has been successfully changed by running the following command:
    

    OpenAI2

    This command will return the user account with the userid "newusername", which should now have the new userid that you specified.
    

    Notice how the code segments even provide you with a COPY Code Link!

    Now that’s darned IMPRESSIVE if you ask me!

    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!
    Computer Specs

    • This topic was modified 9 months, 3 weeks ago by RetiredGeek.
    8 users thanked author for this post.
    Viewing 21 reply threads
    Author
    Replies
    • #2506169

      Many thanks for the post, RG… which I find quite scary.

      Do you have a LifeHacker link? (I couldn’t find one… searches on LifeHacker for ‘Open AI’ or ‘OpenAI’ return zero results.)

      I’m still – several years on – still dipping my toes into PowerShell (which I find overly convoluted in comparison to other scripting solutions yet very often more powerful… hence why I tend to use it more often).

    • #2506199

      Now that’s darned IMPRESSIVE if you ask me!

      Why is it impressive ? Some programmer wrote the code for the “AI”. It is not like a super computer with awareness wrote it.

      • #2506292

        Alex,

        I think it’s impressive beacuse:

        1. The AI parsed the text correctly.
        2. It was smart enough to find the exactly correct answer.
        3. It not only found the correct answer but explained exactly what it was doing in easy to understand text.
        4. It knew it was code so it placed it in a copyable code block w/link

        Maybe I’m just easily impressed but having used and discarded many code generators in the past I’m a bit jaded.

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

        4 users thanked author for this post.
        • #2506314

          The AI parsed the text correctly.

          There is no such thing as AI. Its a hoax just like crypto currency, blockchain, NFT, Metaverse…and it is NOT a IT.
          It is just software.

        • #2506324

          Apologies in advance for contradicting, but this isn’t what ChatGPT does. It is not a search engine and it does not copy and paste what someone wrote for it. It is an AI that has been trained via various types of machine learning, and thus it creates brand new results based on the patterns it has learned during its learning phase. Its creators have not gone and created an if statement saying that this is the answer that should be given if someone asks RetiredGeek’s question – it has learnt this itself by recognising patterns, in a similar way to how a human would learn something.

          AI is very much ‘a thing’, and, unlike crypto and NFTs, will completely revolutionise the world as we know it. Is an AI with human-level intelligence 10 or 20 years away? No. But if you’re looking for an impact, within 50 years AI will have completely transformed the economy, replacing huge numbers of low-skilled and high-skilled technical jobs with AI workers. I’ve already heard of programmers who have spent the past week doing their jobs by asking ChatGPT to create code and simply copy and pasting it (it can do a lot more complex code than Powershell commands).

    • #2506328

      trained via various types of machine learning,

      Machines don’t learn. They are programmed.

      • #2506335

        Machine learning and programming are two entirely different things. The whole point of machine learning is to solve tasks without explicit programming. Saying that machines can’t learn because they have code is like saying that humans can’t learn because they have brains – the code and the brains are only there as a platform upon which the learning takes place.

        Source: I have studied Artificial Intelligence (including machine learning) at university level. Appeals to authority are always unsatisfying, though, so you don’t have to take my word for it – there are many good resources out there on the subject, which I would encourage anyone with an interest in the future of technology to investigate.

      • #2506372

        Machines don’t learn. They are programmed.

        Yes, up until the point where they can program themselves, then watch out.

        Being 20 something in the 70's was much more fun than being 70 something in the 20's.
    • #2506490

      Machines don’t learn. They are programmed.

      Yes, up until the point where they can program themselves, then watch out.

      That point isn’t yet and its far away if ever.

      • #2507196

        …if ever.

        I’m not so sure you can say that with the utmost of certainty. As shown on the OpenAI page for the ChatGPT experiment, tremendous strides are currently being made in this field.

        1 user thanked author for this post.
        Sky
    • #2507199

      What a great concept! They also have an area that has four demonstrations on the page linked to above by @Sky .

      Now, along the lines of lighter things, how long until someone’s kids start using ChatGPT to do their homework for them??

      Seriously, the possibilities seem endless at this point!

      1 user thanked author for this post.
      Sky
      • #2515143

        you mean how soon DID it happen.

        🍻

        Just because you don't know where you are going doesn't mean any road will get you there.
    • #2507221

      In terms of a computer programming itself, one could argue that we are already in a black box scenario, in the sense that if you asked the people who have created ChatGPT how it arrives at its answers they wouldn’t be able to tell you, because it has adjusted its models itself with so much data that it is far too complex for a human to understand.

      As mentioned earlier, this isn’t really ‘programming’, though, as ChatGPT has not adjusted its ‘brain’, but rather it’s adjusted its ‘mind’ through learning.

      There really are tremendous strides being made, though, as Bob99 says. It is notable, though, that even ChatGPT doesn’t use unsupervised learning, which many people see as needed to emulate human intelligence completely, while others think that quantum computing will be required to full replicate the complexity of biological brains, something which is a long long way away, partly due to incredible energy requirements.

      Personally, despite wavy’s joke, I see the near future of AI as more of a huge economic disruptor rather than sentience.

       

      • #2507293

        10 Dangerous Things that the Internet’s Favorite ChatGPT is Capable of Doing

        ..As every coin has two sides, there are many dangerous things that the Internet’s favorite ChatGPT can do. Many Twitter users have come to realize that ChatGPT could potentially be used for both good and evil.

        ChatGPT Lack Morals

        ChatGPT Can Write Phishing Emails Without Typos

        It Can Write Software and Malware

        It’s Capable of Being Sexist, Racist

        It’s ‘Harmful’ to StackOverflow’s Business Model

        ChatGPT: ‘Selfish’ Humans ‘Deserve to be Wiped Out

        Revolutionize the Workplace

        It Could Redefine Supply, Demand, and Economy

        It Can’t Please Everyone on Sensitive Matters

        It’s Convincing Even When It’s Wrong..

        ChatGPT is a bullshit generator. But it can still be amazingly useful

        The philosopher Harry Frankfurt defined bullshit as speech that is intended to persuade without regard for the truth. By this measure, OpenAI’s new chatbot ChatGPT is the greatest bullshitter ever.
        Large Language Models (LLMs) are trained to produce plausible text, not true statements. ChatGPT is shockingly good at sounding convincing on any conceivable topic. But OpenAI is clear that there is no source of truth during training…

        Yet, there are three kinds of tasks for which ChatGPT and other LLMs can be extremely useful, despite their inability to discern truth in general:

        Tasks where it’s easy for the user to check if the bot’s answer is correct, such as debugging help.

        Tasks where truth is irrelevant, such as writing fiction.

        Tasks for which there does in fact exist a subset of the training data that acts as a source of truth, such as language translation…

        1 user thanked author for this post.
        Sky
    • #2514872

      Microsoft and OpenAI Working on ChatGPT-Powered Bing in Challenge to Google

      Microsoft could soon get a return on its $1 billion investment in OpenAI, creator of the ChatGPT chatbot, which gives humanlike text answers to questions.
      Microsoft is preparing to launch a version of its Bing search engine that uses the artificial intelligence behind ChatGPT to answer some search queries rather than just showing a list of links, according to two people with direct knowledge of the plans. Microsoft hopes the new feature, which could launch before the end of March, will help it outflank Google, its much bigger search rival…

      • #2514878

        NYC education department blocks ChatGPT on school devices, networks

        New York City students and teachers can no longer access ChatGPT — the new artificial intelligence-powered chatbot that generates stunningly cogent and lifelike writing — on education department devices or internet networks, agency officials confirmed Tuesday.

        The education department blocked access to the program, citing “negative impacts on student learning, and concerns regarding the safety and accuracy of content,” a spokesperson said. The move from the nation’s largest school system could have ripple effects as districts and schools across the country grapple with how to respond to the arrival of the dynamic new technology…

    • #2515144

      This is for the NON-BELIVERS out there!

      My Query:
      Write a PowerShell program to install USBDLM

      Here is a PowerShell script that will install the USBDLM software on a Windows machine:

      Code:
      # Check if USBDLM is already installed
      $installed = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "USBDLM*"}
      if ($installed) {
          # USBDLM is already installed
          Write-Output "USBDLM is already installed on this system."
      } else {
          # Download the USBDLM installer
          Invoke-WebRequest -Uri "https://www.uwe-sieber.de/usbdlm_e.html" -OutFile "usbdlm.exe"
      
          # Install USBDLM
          Start-Process -FilePath .\usbdlm.exe -ArgumentList '/S' -Wait
      
          # Clean up the installer file
          Remove-Item .\usbdlm.exe
      }
      

      This script will check if USBDLM is already installed on the system. If it is, it will display a message saying that it is already installed. If it is not installed, the script will download the USBDLM installer from the official website and then run it with the ‘/S’ argument to perform a silent installation. Finally, it will clean up the installer file by deleting it.

      Note that this script assumes that you have an internet connection and that you have the necessary permissions to install software on the system.

      Now that goes above and beyond what I asked it to do including finding the program on the internet!

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #2515159

      Ok,

      It ain’t perfect! The code has two problems:

      1. The program is not an .exe but rather a service. Thus you have to check for services to see if it is already installed.
      2. The download package I wanted to use is a .msi (Microsoft Installer) thus I had to make the appropriate changes to the download file and the use of it.

      Once that was done it worked flawlessly.

      Changing the request to:
      Write a PowerShell program to install USBDLM service using a msi package for 64 bit

      Fixed problem #2 but still tried to check installation the wrong way.

      Not quite sure how to get it to check services vs installed programs.

      For those who might be interested here is the fully correct answer:

      Code:
      # Check if USBDLM is already installed
      $installed = Get-Service -Name "USBDLM*"
        
      if ($installed) {
          # USBDLM is already installed
          Write-Output "USBDLM is already installed on this system."
      } else {
          # Download the USBDLM installer
          $IWRArgs = @{Uri = "https://www.uwe-sieber.de/files/usbdlm_x64.msi" 
                       OutFile = "usbdlm_x64.msi"}
          Invoke-WebRequest @IWRArgs
      
          # Install USBDLM
          Start-Process -FilePath .\usbdlm_x64.msi -ArgumentList '/Q' -Wait
      
          # Clean up the installer file
              Remove-Item .\usbdlm_x64.msi
      }
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      1 user thanked author for this post.
      • #2515287

        The code looks elegant: software poetry.

        On permanent hiatus {with backup and coffee}
        offline▸ Win10Pro 2004.19041.572 x64 i3-3220 RAM8GB HDD Firefox83.0b3 WindowsDefender
        offline▸ Acer TravelMate P215-52 RAM8GB Win11Pro 22H2.22621.1265 x64 i5-10210U SSD Firefox106.0 MicrosoftDefender
        online▸ Win11Pro 22H2.22621.1992 x64 i5-9400 RAM16GB HDD Firefox116.0b3 MicrosoftDefender
    • #2515172

      Hey RG… I can see that Open AI has peaked your interest. It’s good to read.

      I think we all need to have something grab our attention and make us think… “hey, how far can I take this… it intrigues me!”

      Keep posting. 🙂

      1 user thanked author for this post.
    • #2530277

      Google’s MusicLM to write music for you from text.

      We introduce MusicLM, a model generating high-fidelity music from text descriptions such as “a calming violin melody backed by a distorted guitar riff”. MusicLM casts the process of conditional music generation as a hierarchical sequence-to-sequence modeling task, and it generates music at 24 kHz that remains consistent over several minutes. Our experiments show that MusicLM outperforms previous systems both in audio quality and adherence to the text description. Moreover, we demonstrate that MusicLM can be conditioned on both text and a melody in that it can transform whistled and hummed melodies according to the style described in a text caption. To support future research, we publicly release MusicCaps, a dataset composed of 5.5k music-text pairs, with rich text descriptions provided by human experts

    • #2530947

      Hey Y’all,

      Here’s my latest attempt to get AI to write good code. It took a couple of tries but the feature of ChatGPT that allows you to add refinements to previous queries seems to work quite well. You just keep adding information until it get’s it the way you want it. Of course, this does require that you have a clue as to what you want!

      Initial Query:
      write a powershell program to add a series of folders to a base folder and include error checking for existing directories so they are not overwritten

      Initial Response:
      Here’s a PowerShell script to add a series of folders to a base folder and check for existing directories to avoid overwriting:

      Code:
      $baseFolder = "C:\Example\Base"
      $folderNames = @("Folder1", "Folder2", "Folder3")
      
      foreach ($folderName in $folderNames) {
      $fullPath = Join-Path $baseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      New-Item -ItemType Directory -Path $fullPath
      Write-Host "The folder $fullPath was created."
      }
      }
      

      This script creates a base folder at C:\Example\Base and an array of folder names, $folderNames, which you can modify as needed. The foreach loop iterates over each folder name and creates the full path by joining the base folder and the folder name using the Join-Path cmdlet.

      The Test-Path cmdlet is used to check if the folder already exists. If it does, the script displays a warning message using the Write-Warning cmdlet. If it doesn’t exist, the script creates the folder using the New-Item cmdlet with the -ItemType parameter set to Directory and the -Path parameter set to the full path. The script then displays a message to indicate that the folder was created.

      Refinement #1:catch errors if folder creation failsResponse to refinement #1

      Here’s an updated version of the PowerShell script that includes error handling for failed folder creation:

      Code:
      $baseFolder = "C:\Example\Base"
      $folderNames = @("Folder1", "Folder2", "Folder3")
      
      foreach ($folderName in $folderNames) {
      $fullPath = Join-Path $baseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      try {
      New-Item -ItemType Directory -Path $fullPath
      Write-Host "The folder $fullPath was created."
      } catch {
      Write-Error "An error occurred while creating the folder $fullPath. Error message: $_"
      }
      }
      }
      

      This script includes error handling using a try-catch block. The try block creates the folder using the New-Item cmdlet, and if an error occurs, the catch block captures the error and displays an error message using the Write-Error cmdlet, including the error message generated by the system.

      This way, if there’s an issue with folder creation, you will be notified and able to take appropriate action to resolve the issue.

      Refinement #2:
      include the -ErrorAction parameter on the New-Item command and use splatting for the arguments to New-Item

      Response to refinement #2
      Here’s the updated version of the PowerShell script that uses the -ErrorAction parameter and splatting for the arguments to New-Item:

      Code:
      $baseFolder = "C:\Example\Base"
      $folderNames = @("Folder1", "Folder2", "Folder3")
      
      foreach ($folderName in $folderNames) {
      $fullPath = Join-Path $baseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      $arguments = @{
      ItemType = "Directory"
      Path = $fullPath
      ErrorAction = "Stop"
      }
      try {
      New-Item @arguments
      Write-Host "The folder $fullPath was created."
      } catch {
      Write-Error "An error occurred while creating the folder $fullPath. Error message: $_"
      }
      }
      }
      

      In this version of the script, the arguments to New-Item are stored in a hash table, $arguments, and passed to the New-Item cmdlet using splatting (the @ symbol before the variable name). The -ErrorAction parameter is set to “Stop”, which means that if an error occurs, the script will stop and throw an error, instead of continuing to the next iteration.

      This way, if there’s an issue with folder creation, the script will stop and display an error message, allowing you to take appropriate action to resolve the issue.

      Refinement #3:
      convert the code to a function that receives a list of folders to create

      Response to Refinement #3:
      Here’s the PowerShell script converted to a function that receives a list of folders to create:

      Code:
      function Create-Folders {
      [CmdletBinding()]
      param (
      [Parameter(Mandatory=$true)]
      [string]$BaseFolder,
      
      [Parameter(Mandatory=$true)]
      [string[]]$FolderNames
      )
      
      foreach ($folderName in $FolderNames) {
      $fullPath = Join-Path $BaseFolder $folderName
      if (Test-Path $fullPath) {
      Write-Warning "The folder $fullPath already exists. Skipping creation."
      } else {
      $arguments = @{
      ItemType = "Directory"
      Path = $fullPath
      ErrorAction = "Stop"
      }
      try {
      New-Item @arguments
      Write-Host "The folder $fullPath was created."
      } catch {
      Write-Error "An error occurred while creating the folder $fullPath. Error message: $_"
      }
      }
      }
      }
      

      The function, Create-Folders, takes two mandatory parameters: $BaseFolder and $FolderNames. $BaseFolder is the base folder where the new folders will be created, and $FolderNames is an array of strings that represents the names of the folders to create.

      The function uses the same logic as the previous script to create the folders and handle errors. To use the function, simply call it and pass in the desired $BaseFolder and $FolderNames:

      It even provided the calling sequence!

      Code:
      Create-Folders -BaseFolder "C:\Example\Base" -FolderNames @("Folder1", "Folder2", "Folder3")
      

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      1 user thanked author for this post.
    • #2550158

      Hey Y’all,

      Here’s the latest installment of my adventures with Chat-GPT. Although this is not code generation, it shows you what you can get in less than 5 minutes. BTW: I had been googling for a couple of hours and couldn’t find this concise succinct content. Maybe I’m just dense, but I would’ve never figured this out from the information I found googling.

      Here’s the conversation:

      RG:
      Can I connect one of the network ports on my DS220+ NAS directly to one computer while connecting the other one to the network?

      Chat-GPT:
      Yes, it is possible to connect one of the network ports on your Synology DS220+ NAS directly to one computer while connecting the other port to the network.

      This configuration is known as “dual LAN mode,” and it allows for improved network performance and redundancy. By connecting one port directly to a computer, you can create a dedicated high-speed connection between the NAS and that computer, while the other port remains connected to your network to provide access to other devices.

      To set up dual LAN mode on your DS220+, you will need to enable the feature in the Control Panel under “Network” and configure the network settings accordingly. You will also need to configure the network settings on the computer connected directly to the NAS.

      Keep in mind that you will need to use a compatible Ethernet cable to connect the NAS to the computer directly, such as a crossover cable or a straight-through cable with auto-MDI/MDIX support.

      RG:
      Will this cause problems if the directly connected computer has a network connection?

      Chat-GPT:
      No, having a directly connected computer and a network connection at the same time should not cause any problems.

      When you connect the DS220+ to your network, it will obtain an IP address from your router or DHCP server. Similarly, when you connect the DS220+ directly to a computer, the computer will assign an IP address to the DS220+ and create a separate network connection.

      The DS220+ is designed to handle multiple network connections simultaneously, so there should be no issue with having both connections active at the same time. However, keep in mind that you will need to configure the network settings on the computer that is directly connected to the DS220+ to ensure that they are compatible with the NAS.

      Also, if both connections are configured to use the same IP address range, you may run into issues with IP address conflicts. To avoid this, you can configure each connection to use a different IP address range, or you can set up static IP addresses for each connection to ensure that there are no conflicts.

      RG:
      Is it possible to assign different IP ranges to the two network adapters in my DS220+ nas?

      Chat-GPT:
      Yes, it is possible to assign different IP ranges to the two network adapters in your Synology DS220+ NAS.

      To configure two different IP ranges for the two network adapters, you will need to set up two separate network interfaces on the NAS. Here’s how you can do it:

      1. Open the Control Panel on your DS220+ and navigate to “Network” > “Network Interface.”
      2. Click the “Create” button to create a new network interface.
      3. In the “Create Network Interface” dialog box, select the “Create Bond” option, and choose “Active Backup” or “IEEE 802.3ad Dynamic Link Aggregation” as the bonding mode, depending on your preference.
      4. Configure the network settings for the first network interface, including the IP address, subnet mask, default gateway, and DNS servers. Make sure to choose a different IP range than your main network for this interface.
      5. Click the “OK” button to save the settings and create the first network interface.
      6. Repeat steps 2-5 to create a second network interface with a different IP range.

      Once you have set up the two network interfaces, you can connect each adapter to a different network port and configure your computer to use the appropriate IP range to connect to the DS220+. This will allow you to have two separate network connections to the NAS, each with its own IP range, providing greater flexibility and control over your network setup.

      ———
      Any networking gurus out there that want to check the accuracy of the above I’d appreciate it as it sure seems plausible to me! I’m ordering the second network card shortly to test this theory.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      1 user thanked author for this post.
    • #2554189

      I took Rick Corbett’s cool script to show a visual indication on the task bar of the User / Admin status and fed it to Chat-GPT.
      Then I instructed it to convert it to powershell and here’s what I got.

      RetiredGeek:

      ; Icons by Axialis (https://www.axialis.com/)
      #SingleInstance On
      If !A_IsAdmin = 1
      Menu, Tray, Icon, C:\_MY\Resources\User-Warn.ico ; use a valid icon file name
      else
      Menu, Tray, Icon, C:\_MY\Resources\User-OK.ico ; use a valid icon file name
      Return
      
      Esc::ExitApp
      

      Chat-GPT:

      This is an AutoHotkey script that sets the system tray icon of the script based on whether it is being run with administrator privileges or not.

      The script first checks whether the script is running with administrator privileges using the “!A_IsAdmin” variable. If the script is not running with administrator privileges, it sets the tray icon to “User-Warn.ico”, which is an icon that suggests a warning or caution. If the script is running with administrator privileges, it sets the tray icon to “User-OK.ico”, which is an icon that suggests everything is okay.

      The script also sets the script to run as a single instance using the “#SingleInstance On” command. This ensures that only one instance of the script can run at a time.

      Finally, the script assigns the “Esc” key to exit the script using the “Esc::ExitApp” command.

      RetiredGeek:
      convert to powershell

      Chat-GPT:
      Here’s the equivalent PowerShell script for the AutoHotkey script you provided:

      # Set the system tray icon based on whether the script is running with admin privileges or not
      if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
          $icon = New-Object System.Drawing.Icon "C:\_MY\Resources\User-Warn.ico"
      } else {
          $icon = New-Object System.Drawing.Icon "C:\_MY\Resources\User-OK.ico"
      }
      [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
      $notifyIcon = New-Object System.Windows.Forms.NotifyIcon
      $notifyIcon.Icon = $icon
      $notifyIcon.Visible = $true
      
      # Set the script to exit when the Esc key is pressed
      Add-Type -AssemblyName WindowsBase
      $global:myEvent = [WindowsBase.SystemEvents]
      $global:myEvent::SessionEnding += { $notifyIcon.Dispose(); Exit-PSSession }
      

      This PowerShell script uses the same logic as the AutoHotkey script to set the system tray icon based on whether the script is running with admin privileges or not. It uses the WindowsPrincipal class to check if the current user has administrative privileges.

      To create a system tray icon, the script uses the System.Drawing.Icon and System.Windows.Forms.NotifyIcon classes from the .NET Framework. The script creates an instance of the NotifyIcon class and sets its Icon property to the appropriate icon file. It also sets the Visible property to $true to display the system tray icon.

      Finally, the script uses the SystemEvents class to handle the “SessionEnding” event, which is raised when the user logs off or shuts down the computer. The script disposes of the system tray icon and exits the PowerShell session when this event is raised.
      ——————– End Chat-GPT response ——————–

      Now tell me this isn’t a great way to learn to program in in a different language even if you don’t know the source language, which BTW I don’t!

      NOTE: The code has some problems but it’s on the right track!

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

      1 user thanked author for this post.
    • #2554250

      RG,

      I wrote my AHK script in, essentially, 5 lines of code to do what was asked for. The other 2 lines were niceties… not exactly necessary, but perhaps helpful.

      I’m flattered that my post provoked your query to Chat-GPT… and look forward to any further results. 🙂

      The output so far is really impressive, especially its understanding of AutoHotkey syntax and my script’s very, very simple if-else conditional coding structure.

      BTW, my friend… I don’t for one moment believe you didn’t understand the incredibly simple AHK code. Despite my very poor documentation of such a short and simple AHK script, it’s written in a scripting language that more or less replicates Engish in pseudo-code…

      (unlike Powershell with its ‘pipeline’, dot notation’, ‘splatting’ and ‘assemblies’, for example. Compare the English… ROFL)

    • #2554261

      Hmm… something’s been niggling…

      With hindsight, I should probably make it much clearer what the different ‘signed in’ states represent, i.e. that running as Standard was preferable to running as Admin.

      Perhaps I should also have used built-in icons (rather than rely on third-party ones) or construct my own [coloured] glyphs to make the different states clearer – like A (for Admin) vs S (for Standard)… or a red blob (for Admin) vs a green blob (for Standard).

      So, whilst the basic code caters for each if… else continguency… with hindsight, I think you may need to think about your target audience.

       

    • #2554264

      Rick,

      Having a bit of a problem with this one I have the basic code but am having it a problem getting it to show the right icon? I agree that simpler easier to discern would be a great help.

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #2554688

      Having a bit of a problem with this one I have the basic code but am having it a problem getting it to show the right icon? I agree that simpler easier to discern would be a great help.

      Maybe use just a coloured glyph/blob rather than an icon? Is that possible? With AutoHotkey you can change the colour of text strings as needed, even if it’s just a hard coded space (which creates a coloured glyph).

      I’ll admit that I haven’t yet tried that with AutoHotkey‘s Menu, Tray method yet but I don’t see why it wouldn’t work with a string character instead of an icon… and should be much easier to implement?

      I don’t know much about PowerShell graphics (or indeed PowerShell full stop… 🙂 ) but would that be easier?

      OP just wants a visual indicator, right? No fancy stuff required… just KISS? 🙂

    • #2554690

      RG… are you sure that you don’t want to look more at AutoHotkey?

      I looked at:

      if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
          $icon = New-Object System.Drawing.Icon "C:\_MY\Resources\User-Warn.ico"
      } else {
          $icon = New-Object System.Drawing.Icon "C:\_MY\Resources\User-OK.ico"
      }

      then compared it to:

      If !A_IsAdmin = 1
      Menu, Tray, Icon, C:\_MY\Resources\User-Warn.ico
      else
      Menu, Tray, Icon, C:\_MY\Resources\User-OK.ico
      

      No wonder that I struggle with PowerShellAHK is much more understandable in pseudo-code English. 🙂

    • #2554693

      PS – I asked a (pre-retirement) work colleague who’s an enterprise-wide app coder and he tells me I need to create a ‘PowerShell v5 Host (Windows Tray App)’.

      I have absolutely no idea what he means… but I guess it must be possible to create something that exists solely in the Notification Area.

    • #2554704

      I’m trying to work through Create your own PowerShell systray/taskbar tool but my lack of familiarity with PowerShell scuppers me time and time again.

      Fun though… I guess I must be into sado-masochism after all.

      Hmmm… I like KISS. I still prefer AutoHotkey to get things done way quicker than PowerShell. Five lines and the OP’s request was accomplished. PowerShell? Well… the (painful) journey continues. 🙂

    • #2568185

      Should I use gpp chat to learn a programming language?

      • #2568206

        Try it and let us know.

        teach me to program in powershell

        cheers, Paul

      • #2568278

        Zimbof,

        If you already know another programming language, definitely YES! You can easily write a routine in the language you know and submit it to Chat-GPT and ask it to convert it to another language. That way you learn the command structure and syntax of the new language by comparing it to the language you already know. Later, you can ask it to do new things and you’ll have enough of a background to understand what the output is doing.

        However, if you do not know how to program already it’s a definite NO! In this case I’d suggest getting a good book on introduction to programming, using the language you want to learn, or taking an introductory program at a community college or online. Once you have a good foundation then you can explore using your new found knowledge to expand your capabilities.

        Caution: Chat-GPT has been known to give thoroughly convincing answers that are entirely WRONG! I’ve encountered this myself when asking it to do something in PowerShell. It’s the old Trust but VERIFY!

        May the Forces of good computing be with you!

        RG

        PowerShell & VBA Rule!
        Computer Specs

        1 user thanked author for this post.
    Viewing 21 reply threads
    Reply To: Use Open AI to write code for you?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: